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

5 ビュー (過去 30 日間)
pandu hanifa
pandu hanifa 2018 年 12 月 20 日
回答済み: Brian Hart 2018 年 12 月 20 日
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 Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by