Matlab多变量最小化

时间:2015-06-06 10:31:31

标签: algorithm matlab image-processing optimization minimization

我正在尝试开发Polesel等人描述的自适应非锐化算法。在文章"通过自适应反锐化掩模的图像增强" (link to the article)。算法的核心是最小化定义为:

的成本函数
J(m,n) = E[e(m,n)^2] = E[(gd(m,n)-gy(m,n))^2]

其中E []是统计期望,gy(m,n)是:

gy(m,n) = gx(m,n) + lambda1(m,n)*gzx(m,n) + lambda2(m,n)*gzy(m,n);

我想为每个像素找到lambda1和lambda2,以便最小化每个像素中的成本函数。 这是我到目前为止编写的代码:

function [ o_sharpened_image ] = AdaptativeUnsharpMask( i_image , t1, t2)
%ADAPTATIVEUNSHARPMASK Summary of this function goes here
%   Detailed explanation goes here
if isa(i_image,'dip_image')
    i_image = dip_array(i_image);
end
if ~isfloat(i_image)
    i_image = im2double(i_image);
end
adh = 4;
adl = 3;
g = [-1 -1 -1; -1 8 -1; -1 -1 -1];
dim = size(i_image);
lambda_x = 0.5*ones(dim);
lambda_y = 0.5*ones(dim);
z_x  = conv2(i_image,[-1 2 -1],'same');
z_y  = conv2(i_image,[-1; 2; -1],'same');
g_x  = conv2(i_image,g,'same');
g_zx = conv2(z_x,g,'same');
g_zy = conv2(z_y,g,'same');

a = ones(dim);
variance_map = colfilt(i_image,[3 3],'sliding',@var);
a(variance_map >= t1 & variance_map < t2) = adh;
a(variance_map >= t2) = adl;
g_d = a.*g_x;

lambda = [lambda_x lambda_y];

lambda0 = lambda;
lambda_min = lsqnonlin(@(lambda) UnsharpCostFunction(lambda,g_d,g_zx,g_zy),lambda0); 

o_sharpened_image = i_image + lambda_min(:,1:size(i_image,2)).*z_x + lambda_min(:,size(i_image,2)+1:end).*z_y;

end

这里是成本函数的代码:

function [ J ] = UnsharpCostFunction( i_lambda, i_gd, i_gzx, i_gzy )
%UNSHARPCOSTFUNCTION Summary of this function goes herek

gy = i_gd + i_lambda(:,1:size(i_gd,2)).*i_gzx + i_lambda(:,size(i_gd,2)+1:end).*i_gzy;
J = mean((i_gd(:) - gy(:)).^2);

end

对于每次迭代,我在命令窗口上打印J函数的值,它始终是相同的。我做错了什么?

谢谢。

0 个答案:

没有答案