为计算输入图像的增强功能,我编写了以下代码:
Ig = rgb2gray(imread('test.png'));
N = numel(Ig);
meanTotal = mean2(Ig);
[row,cal] = size(Ig);
IgTransformed = Ig;
n = 3;
a = 1;
b = 1;
c = 1;
k = 1;
for ii=2:row-1
for jj=2:cal-1
window = Ig(ii-1:ii+1,jj-1:jj+1);
IgTransformed(ii,jj) = ((k*meanTotal)/(std2(window) + b))*abs(Ig(ii,jj)-c*mean2(window)) + mean2(window).^a;
end
end
如何减少计算时间? 显然,其中一个因素是每次应该在循环中制作的小窗口(3x3)。
答案 0 :(得分:2)
你去吧 -
Igd = double(Ig);
std2v = colfilt(Igd, [3 3], 'sliding', @std);
mean2v = conv2(Igd,ones(3),'same')/9;
Ig_out = uint8((k*meanTotal)./(std2v + b).*abs(Igd-cal*mean2v) + mean2v.^a);
这也将改变边界元素,如果不需要,可以将其重新设置为原始边界元素,只需几步即可 -
Ig_out(:,[1 end]) = Ig(:,[1 end])
Ig_out([1 end],:) = Ig([1 end],:)