how can i make the result number from convolution become positive?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
this is the result![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199466/Capture.png)
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199466/Capture.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);
0 commentaires
Réponses (1)
Brian Hart
le 20 Déc 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).
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!