필터 지우기
필터 지우기

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

조회 수: 1 (최근 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 CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by