% Parse inputs to verify valid function calling syntaxes and arguments
parse_inputs(varargin{:});

% 1. Prepare parameters for iterations
%
% Create indexes for image according to the sampling rate
idx = repmat({':'},[1 length(sizeI)]);

wI = max(WEIGHT.*(READOUT + J{1}),0);% at this point - positivity constraint

fw = fftn(WEIGHT);
clear WEIGHT;
DAMPAR22 = (DAMPAR.^2)/2;

% 2. L_R Iterations
%
lambda = 2*any(J{4}(:)~=0);
for k = (lambda + 1) : (lambda + NUMIT),

% 2.a Make an image and PSF predictions for the next iteration

if k > 2,% image
lambda = (J{4}(:,1).'*J{4}(:,2))/(J{4}(:,2).'*J{4}(:,2) + eps);
lambda = max(min(lambda,1),0);
% stability enforcement lambda(0,1)之间
end
Y = max(J{2} + lambda*(J{2} - J{3}),0);% image positivity constraint

if k > 2,% PSF
lambda = (P{4}(:,1).'*P{4}(:,2))/(P{4}(:,2).'*P{4}(:,2) + eps);
lambda = max(min(lambda,1),0);% stability enforcement

end
B = max(P{2} + lambda*(P{2} - P{3}),0);% PSF positivity constraint
sumPSF = sum(B(:));
B = B/(sum(B(:)) + (sumPSF==0)*eps);% normalization is a necessary constraint,
% because given only input image, the algorithm cannot even know how much
% power is in the image vs PSF. Therefore, we force PSF to satisfy this
% type of normalization: sum to one.

% 2.b Make core for the LR estimation

% 2.c Determine next iteration image & apply positivity constraint
J{3} = J{2};
H = psf2otf(P{2},sizeI);
scale = real(ifftn(conj(H).*fw)) + sqrt(eps);
J{2} = max(Y.*real(ifftn(conj(H).*CC))./scale,0);
clear scale;
J{4} = [J{2}(:)-Y(:) J{4}(:,1)];
clear Y H;

% 2.d Determine next iteration PSF & apply positivity constraint + normalization
P{3} = P{2};
H = fftn(J{3});
scale = otf2psf(conj(H).*fw,sizePSF) + sqrt(eps);
P{2} = max(B.*otf2psf(conj(H).*CC,sizePSF)./scale,0);
clear CC H;

sumPSF = sum(P{2}(:));
P{2} = P{2}/(sumPSF + (sumPSF==0)*eps);

if ~isempty(FunFcn),
FunArg{1} = P{2};
P{2} = feval(FunFcn,FunArg{:});
end;
P{4} = [P{2}(:)-B(:) P{4}(:,1)];
end
clear fw wI;

% 3. Convert the right array (for cell it is first array, for notcell it is
% second array) to the original image class & output the whole
num = 1 + strcmp(classI{1},'notcell');
if ~strcmp(classI{2},'double'),
J{num} = images.internal.changeClass(classI{2},J{num});
end

if num == 2,% the input & output is NOT a cell
P = P{2};
J = J{2};
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function: parse_inputs
= parse_inputs(varargin)
%
% Outputs:
% I=J{1} the input array (could be any numeric class, 2D, 3D)
% P=P{1} the operator that distorts the ideal image
%
% Defaults:
%
NUMIT=[];NUMIT_d = 10; % Number of iterations, usually produces good
% result by 10.
DAMPAR =[];DAMPAR_d = 0;% No damping is default
WEIGHT =[]; % All pixels are of equal quality, flat-field is one
% back/fore/ground noise associated with CCD camera.
% Or the Image is corrected already for this noise by user.
FunFcn = '';FunFcn_d = '';
FunArg = {};FunArg_d = {};
funnum = [];funnum_d = nargin+1;

narginchk(2,inf);% no constraint on max number
% because of FUN args

% First, assign the inputs starting with the cell/not cell image & PSF
switch iscell(varargin{1}) + iscell(varargin{2}),

case 0, % no-cell array is used to do a single set of iterations
classI{1} = 'notcell';

J{1} = varargin{1};% create a cell array in order to do the iterations
P{1} = varargin{2};
case 1,
error(message('images:deconvblind:IandInitpsfMustBeOfSameType'))
case 2,% input cell is used to resume the interrupted iterations or
classI{1} = 'cell';% to interrupt the iteration to resume them later
J = varargin{1};
P = varargin{2};
if length(J)~=length(P),
error(message('images:deconvblind:IandInitpsfMustBeOfSameSize'))
end
end;

% check the Image, which is the first array of the J-cell
classI{2} = class(J{1});

validateattributes(J{1},{'uint8' 'uint16' 'double' 'int16' 'single'},...
{'real' 'nonempty' 'finite'},mfilename,'I',1);

if prod(sizeI)<2,
error(message('images:deconvblind:inputImageMustHaveAtLeast2Elements'))
elseif ~isa(J{1},'double'),
J{1} = im2double(J{1});
end

% check the PSF, which is the first array of the P-cell
validateattributes(P{1},{'uint8' 'uint16' 'double' 'int16' 'single'},...
{'real' 'nonempty' 'finite' 'nonzero'},mfilename,'INITPSF',2);

if prod(sizePSF)<2,
error(message('images:deconvblind:initPSFMustHaveAtLeast2Elements'))
elseif ~isa(P{1},'double'),
P{1} = double(P{1});
end

% now since the image&PSF are OK&double, we assign the rest of the J & P cells
len = length(J);
if len == 1,% J = {I} will be reassigned to J = {I,I,0,0}
J{2} = J{1};
J{3} = 0;
J{4}(prod(sizeI),2) = 0;
P{2} = P{1};
P{3} = 0;
P{4}(prod(sizePSF),2) = 0;
elseif len ~= 4,% J = {I,J,Jm1,gk} has to have 4 or 1 arrays
error(message('images:deconvblind:inputCellsMustBe1or4ElementNumArrays'))
else % check if J,Jm1,gk are double in the input cell
if ~all([isa(J{2},'double'),isa(J{3},'double'),isa(J{4},'double')]),
error(message('images:deconvblind:ImageCellElementsMustBeDouble'))
elseif ~all([isa(P{2},'double'),isa(P{3},'double'),isa(P{4},'double')]),
error(message('images:deconvblind:psfCellElementsMustBeDouble'))
end
end;

% Second, Find out if we have a function to put additional constraints on the PSF
%

function_classes = {'inline','function_handle','char'};
idx = [];
for n = 3:nargin,
idx = strmatch(class(varargin{n}),function_classes);
if ~isempty(idx),
[FunFcn,msgStruct] = fcnchk(varargin{n}); %only works on char, making it inline
if ~isempty(msgStruct)
error(msgStruct)
end
FunArg = [{0},varargin(n+1:nargin)];
try % how this function works, just in case.
feval(FunFcn,FunArg{:});
catch ME
Ftype = {'inline object','function_handle','expression ==>'};
Ffcnstr = {' ',' ',varargin{n}};
error(message('images:deconvblind:userSuppliedFcnFailed', Ftype{ idx }, Ffcnstr{ idx }, ME.message))
end
funnum = n;
break
end
end

if isempty(idx),
FunFcn = FunFcn_d;
FunArg = FunArg_d;
funnum = funnum_d;
end

%
% Third, Assign the inputs for general deconvolution:
%
if funnum>7
error(message('images:validate:tooManyInputs',mfilename));
end

switch funnum,
case 4,% deconvblind(I,PSF,NUMIT,fun,...)
NUMIT = varargin{3};
case 5,% deconvblind(I,PSF,NUMIT,DAMPAR,fun,...)
NUMIT = varargin{3};
DAMPAR = varargin{4};
case 6,% deconvblind(I,PSF,NUMIT,DAMPAR,WEIGHT,fun,...)
NUMIT = varargin{3};
DAMPAR = varargin{4};
WEIGHT = varargin{5};
NUMIT = varargin{3};
DAMPAR = varargin{4};
WEIGHT = varargin{5};
end

% Forth, Check validity of the gen.conv. input parameters:
%
% NUMIT check number of iterations
if isempty(NUMIT),
NUMIT = NUMIT_d;
else %verify validity
validateattributes(NUMIT,{'double'},...
{'scalar' 'positive' 'integer' 'finite'},...
mfilename,'NUMIT',3);
end

% DAMPAR check damping parameter
if isempty(DAMPAR),
DAMPAR = DAMPAR_d;
elseif (numel(DAMPAR)~=1) && ~isequal(size(DAMPAR),sizeI),
error(message('images:deconvblind:damparMustBeSizeOfInputImage'));
elseif ~isa(DAMPAR,classI{2}),
error(message('images:deconvblind:damparMustBeSameClassAsInputImage'));
elseif ~strcmp(classI{2},'double'),
DAMPAR = im2double(DAMPAR);
end

if ~isfinite(DAMPAR),
error(message('images:deconvblind:damparMustBeFinite'));
end

% WEIGHT check weighting
if isempty(WEIGHT),
WEIGHT = ones(sizeI);
else
numw = numel(WEIGHT);
validateattributes(WEIGHT,{'double'},{'finite'},mfilename,'WEIGHT',5);
if (numw ~= 1) && ~isequal(size(WEIGHT),sizeI),
error(message('images:deconvblind:weightMustBeSizeOfInputImage'));
elseif numw == 1,
WEIGHT = repmat(WEIGHT,sizeI);
end;
end

elseif ~strcmp(classI{2},'double'),
end
end;

2个回答

《MySQL 性能优化》之理解 MySQL 体系结构

python自动下载图片

【前言】 　　收到一封来信，赶上各种事情拖了几日，利用今天要放下工作的时机，做个回复。 　　2020年到了，就以这一封信，作为开年标志吧。 【正文】 　　您好，我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。 　　先说一下我的基本情况，高考失利，不想复读，来到广州一所大专读计算机应用技术专业。学校是偏艺术类的，计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...

【CSDN编者按】1月2日，阿里巴巴发布《达摩院2020十大科技趋势》，十大科技趋势分别是：人工智能从感知智能向认知智能演进；计算存储一体化突破AI算力瓶颈；工业互联网的超融合；机器间大规模协作成为可能；模块化降低芯片设计门槛；规模化生产级区块链应用将走入大众；量子计算进入攻坚期；新材料推动半导体器件革新；保护数据隐私的AI技术将加速落地；云成为IT技术创新的中心 。 新的画卷，正在徐徐展开。...

Python+OpenCV实时图像处理

2020年一线城市程序员工资大调查

python爬取百部电影数据，我分析出了一个残酷的真相
2019年就这么匆匆过去了，就在前几天国家电影局发布了2019年中国电影市场数据，数据显示去年总票房为642.66亿元，同比增长5.4%；国产电影总票房411.75亿元，同比增长8.65%，市场占比 64.07%；城市院线观影人次17.27亿，同比增长0.64%。 看上去似乎是一片大好对不对？不过作为一名严谨求实的数据分析师，我从官方数据中看出了一点端倪：国产票房增幅都已经高达8.65%了，为什...

Windows可谓是大多数人的生产力工具，集娱乐办公于一体，虽然在程序员这个群体中都说苹果是信仰，但是大部分不都是从Windows过来的，而且现在依然有很多的程序员用Windows。 所以，今天我就把我私藏的Windows必装的软件分享给大家，如果有一个你没有用过甚至没有听过，那你就赚了????，这可都是提升你幸福感的高效率生产力工具哦！ 走起！???? NO、1 ScreenToGif 屏幕，摄像头和白板...

C++(数据结构与算法):62---搜索树（二叉搜索树、索引二叉搜索树）

AI 没让人类失业，搞 AI 的人先失业了

2020年，冯唐49岁：我给20、30岁IT职场年轻人的建议

B站是个宝，谁用谁知道???? 作为一名大学生，你必须掌握的一项能力就是自学能力，很多看起来很牛X的人，你可以了解下，人家私底下一定是花大量的时间自学的，你可能会说，我也想学习啊，可是嘞，该学习啥嘞，不怕告诉你，互联网时代，最不缺的就是学习资源，最宝贵的是啥？ 你可能会说是时间，不，不是时间，而是你的注意力，懂了吧！ 那么，你说学习资源多，我咋不知道，那今天我就告诉你一个你必须知道的学习的地方，人称...

leetcode88. 合并两个有序数组

Java校招入职华为，半年后我跑路了

Python全栈 Linux基础之3.Linux常用命令
Linux对文件（包括目录）有很多常用命令，可以加快开发效率：ls是列出当前目录下的文件列表，选项有-a、-l、-h，还可以使用通配符；c功能是跳转目录，可以使用相对路径和绝对路径；mkdir命令创建一个新的目录，有-p选项，rm删除文件或目录，有-f、-r选项；cp用于复制文件，有-i、-r选项，tree命令可以将目录结构显示出来（树状显示），有-d选项，mv用来移动文件/目录，有-i选项；cat查看文件内容，more分屏显示文件内容，grep搜索内容；>、>>将执行结果重定向到一个文件；|用于管道输出。
​两年前不知如何编写代码的我，现在是一名人工智能工程师

loonggg读完需要5分钟速读仅需 2 分钟大家好，我是你们的校长。我知道大家在家里都憋坏了，大家可能相对于封闭在家里“坐月子”，更希望能够早日上班。今天我带着大家换个思路来聊一个问题...
Spring框架|JdbcTemplate介绍

B 站上有哪些很好的学习资源?

24岁的程序员，还在未来迷茫，不知道能不能买得起房子