# Help explain a portion of a code

1 view (last 30 days)
Larissa Monjaraz on 26 Mar 2021
Edited: DGM on 27 Mar 2021
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');
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 on 27 Mar 2021
Edited: DGM on 27 Mar 2021
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:
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).

### Categories

Find more on Image Filtering and Enhancement in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!