フィルターのクリア

Help explain a portion of a code

1 回表示 (過去 30 日間)
Larissa Monjaraz
Larissa Monjaraz 2021 年 3 月 26 日
編集済み: DGM 2021 年 3 月 27 日
Hi, I need help in explaining what the bolded part of the code does. I understand the rest but I'm having a hard time figuring out what the bolded code means. If possible can someone simplify the code to make it easier to understand. Thank you.
file=input('Enter filename: ','s');
im=imread(file);
newim=uint8((zeros(size(im))));
for k=1:3
for i=2:size(im,1)-1
for j=2:size(im,2)-1
pixel=-4*double(im(i,j,k))+double(im(i+1,j,k))+double(im(i-1,j,k))+double(im(i,j+1,k))+double(im(i,j-1,k));
newim(i,j,k)=pixel;
end
end
end
newName=[file(1:find(file=='.')-1),'Outline',file(find(file=='.'):end)];
imwrite(newim,newName);
fprintf('Outline saved to %s\n',newName)

採用された回答

DGM
DGM 2021 年 3 月 27 日
編集済み: DGM 2021 年 3 月 27 日
This appears to be a naive 5-element Laplacian high-pass filter of sorts. You're basically convolving the original image with a filter kernel like this:
inpict=imread('testpicture.jpg');
fk=[0 1 0; ...
1 -4 1; ...
0 1 0];
outpict=imfilter(inpict,fk);
Of course, besides being about 40x faster, this method also correctly pads the image boundary so that edge artifacts aren't generated.
This particular form of Laplacian filter kernel can also be obtained from fspecial by setting its shape parameter to zero:
fk=fspecial('laplacian',0);
If you want to know what that one line means in this context, it is the sum of the product of the filter kernel and the image local to the point (i,j).

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by