How to detect the edge of the photo

I want to detect the photo edge and I turn the outside black color. However the thing is there are some dirty dots on the photo. So when I detect the edge, the dirty pot become the darkest and there is a line appear. I want to know how to remove it.
Below is my program can someone help me check what should I do. Thanks a lot.
I1=imread('C:\Users\Lenovo\Desktop\FYP_P055\Huijie1.jpg');
A=imread('C:\Users\Lenovo\Desktop\FYP_P055\Huijie1.jpg');
imtool(A);
hist(double(A));
I1(I1<40)=0;
A1=hist(double(I1));
hist(double(I1));
[row,col]=size(I1);
I11=I1(1:row/2,1:col/2);
I12=I1(1:row/2,col/2:end);
I21=I1(row/2+1:end,1:col/2);
I22=I1(row/2+1:end,col/2:end);
M11=min(I11,[],1);
M12=min(I12,[],1);
M21=min(I21,[],1);
M22=min(I22,[],1);
for c=1:col/2
for r=1:row/2
if I1(r,c)==M11(c)
min_val_col=c;
min_val_row=r;
for cc=1:min_val_row
I1(cc,min_val_col)=0;
end
end
end
for r=row/2+1:row
if I1(r,c)==M21(c)
min_val_col=c;
min_val_row=r;
for cc=min_val_row:row
I1(cc,min_val_col)=0;
end
end
end
end
for c2=round(col/2):col
c=c2-round(col/2)+1;
for r=1:row/2
if I1(r,c2)==M12(c)
min_val_col=c2;
min_val_row=r;
for cc=1:min_val_row
I1(cc,min_val_col)=0;
end
end
end
for r=row/2+1:row
if I1(r,c2)==M22(c)
min_val_col=c2;
min_val_row=r;
for cc=min_val_row:row
I1(cc,min_val_col)=0;
end
end
end
end
imtool(I1);

2 comentarios

Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 18 de En. de 2016
check demos of image analyst in this website. you will get
Walter Roberson
Walter Roberson el 18 de En. de 2016
imclearborder() ?

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 18 de En. de 2016

0 votos

Easy. Threshold. Take the largest blob, then get its convex hull. See attached demo script below this image it creates:

7 comentarios

huijie Q
huijie Q el 23 de En. de 2016
I still cannot get it. Should I delete my program first or need to add your program in?
huijie Q
huijie Q el 23 de En. de 2016
I cannot get the final masked and the masked image.
Image Analyst
Image Analyst el 23 de En. de 2016
Why not? You can turn my code into a function called GetMaskedImage() or something. What went wrong?
huijie Q
huijie Q el 25 de En. de 2016
Thank you for answering me. But I want it to be detect column by column see which part has lesser intensity. Then It will turn black. If the point is more far away from the original edge, then I reject that point and choose the point near the edge.
Image Analyst
Image Analyst el 25 de En. de 2016
I read it several times but I just cannot understand what that means. Please attach a final output image so I can see what you want.
huijie Q
huijie Q el 11 de Abr. de 2016
I can get the first 3 already. Can you show me your program for how to get final mask and masked image? thanks!
Image Analyst
Image Analyst el 11 de Abr. de 2016
I still don't understand. The demo gives all the images in the figure, including the final mask and masked image. Why do you think it doesn't?

Iniciar sesión para comentar.

Más respuestas (1)

Thorsten
Thorsten el 18 de En. de 2016

0 votos

You can use imfindcircles to detect the circle, and then set all points outside the circle to black. See http://stackoverflow.com/questions/29323640/circle-detection-via-hough-transform

Preguntada:

el 18 de En. de 2016

Comentada:

el 11 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by