admin管理员组文章数量:1405170
I am currently studying convolution in MATLAB and have encountered an issue. The code below is an attempt to manually implement the conv2 function using a for loop.
However, when I compare the convolution result of an image and an HPF (High-Pass Filter) using conv2 with the result from my manually implemented code, there is a discrepancy.
I am not sure where the mistake is. Interestingly, when I implemented an LPF (Low-Pass Filter) in the same way, the difference was zero.
Why does the HPF produce different values?
HPF = [-1 -1 -1;
-1 8 -1;
-1 -1 -1];
%--------------------------using function---------------------------------
HPFimage1 = conv2(grayfun,HPF,'same');
%--------------------------without funtion---------------------------------
%--------------------------zero padding---------------------------------
for i = 1 : row
for j = 1 : col
padding(i+1,j+1) = grayman(i,j);
end
end
% ------------------------------HPF-------------------------
i = 2;
j = 2;
HPFimage2 = zeros(row,col);
for x = 0 : row-1
for y = 0 : col-1
% Extracting and calculating a 3x3 matrix
sumval = 0;
for m = 0 : 2
for n = 0 : 2
sumval = sumval + (padding(x+m+i-1,y+n+j-1)*HPF(m+1,n+1));
end
end
HPFimage2(x+1,y+1) = sumval;
end
end
HPFsubresult = abs(HPFimage1) - abs(HPFimage2);
本文标签: How to Apply the HPF FilterStack Overflow
版权声明:本文标题:How to Apply the HPF Filter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744322515a2600571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论