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

6 Ansichten (letzte 30 Tage)
pandu hanifa
pandu hanifa am 20 Dez. 2018
Beantwortet: Brian Hart am 20 Dez. 2018
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);

Antworten (1)

Brian Hart
Brian Hart am 20 Dez. 2018
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).

Community Treasure Hunt

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

Start Hunting!

Translated by