how can i make the result number from convolution become positive?

3 次查看(过去 30 天)
this is the resultCapture.PNG
and this the script;
img=imread('albert.jpg');
F=size(img);
G = [0 -1 0;-1 4 -1;0 -1 0];
FxG = F;
% Konvolusi
[bf, kf] = size(F);
[bg, kg] = size(G);
m2 = floor(bg/2);
n2 = floor(kg/2);
% Penambahan elemen nol
pad = zeros(bf+4,kf+4);
pad(3:bf+2,3:kf+2) = F;
[b_pad,k_pad] = size(pad);
for i = m2+1 : b_pad-m2;
for j = n2+1 : k_pad-n2;
temp = 0;
for k = -m2: m2;
for l = -n2: n2;
temp = temp + G(k + m2+1,l+n2+1) * pad(i-k,j-l);
end
end
FxG(i,j) = temp;
end
end
FxG = FxG(2:bf+3,2:kf+3);

回答(1 个)

Brian Hart
Brian Hart 2018-12-20
Convolution results can be negative.
If you want only positive results, two options are to either take the absolute value of the result, or find the minimum (negative) value in the result, then add its absolute value to the result (shifting all the values positive).

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by