How do I get rid of the blue screen while dilating an image?

1 view (last 30 days)
Not being allowed to use imdilate for my code, I got no error when I ran my code to dilate the image, however it came up as a blue screen instead of the dilated image. Can anyone help me figure out where the problem is? Thanks
function [img_out] = myDilation(img_in, N)
[m,n]=size(img_in);
img_out= zeros(m,n);
for i=1:m
for j=1:n
if (img_in(i,j)==1)
for k=1:N
for l=1:N
if(img_in(k,l)==1)
c=i+k;
d=j+l;
img_out(c,d)=1;
end
end
end
end
end
end
end

Accepted Answer

Image Analyst
Image Analyst on 14 Mar 2014
You must need to think about what you are doing, that's all. And you'll realize your obvious mistake. The dilation is a local max. You're not doing that at all. Your code is wrong in more than 1 way. For one thing you don't check only on the central pixel, you check for any pixel in the window. Secondly you're not even scanning an NxN window around i,j You need to do
for k = -N : N
for l = -N : N
if(img_in(i + k, j + l) == 1)
img_out(i, j)=1;
break;
Next, this is a double image, not an RGB image, so how did you get blue? Try to just display it like
imshow(img_out, []);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!