function eroded = Erosin(image, template)
%Implementation of erosion operator
%Parameters:Templte and image array of point
%get the image
[irows, icols] = size(image);
[trows, tcols] = size(template);
%create result image
eroded(1:irows, 1:icols) = uint8(0);
%half of template
trhalf = floor(trows/2);
tchalf = floor(tcols/2);
%Erosion
for x = trhalf+1:icols-trhalf
for y = tchalf+1:irows-tchalf
min = 256;
for iwin = 1:tcols
for jwin = 1:trows
xi = x-trhalf-1+iwin;
yi = y-tchalf-1+jwin;
sub = double(image(xi,yi))-double(template(iwin,jwin));
if sub< min & sub >0
min = sub;
end
end
end
eroded(x, y) = uint8(min);
end
end
%Implementation of erosion operator
%Parameters:Templte and image array of point
%get the image
[irows, icols] = size(image);
[trows, tcols] = size(template);
%create result image
eroded(1:irows, 1:icols) = uint8(0);
%half of template
trhalf = floor(trows/2);
tchalf = floor(tcols/2);
%Erosion
for x = trhalf+1:icols-trhalf
for y = tchalf+1:irows-tchalf
min = 256;
for iwin = 1:tcols
for jwin = 1:trows
xi = x-trhalf-1+iwin;
yi = y-tchalf-1+jwin;
sub = double(image(xi,yi))-double(template(iwin,jwin));
if sub< min & sub >0
min = sub;
end
end
end
eroded(x, y) = uint8(min);
end
end