How to detect the edge of the photo
7 views (last 30 days)
Show older comments
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 Comments
Sivakumaran Chandrasekaran
on 18 Jan 2016
check demos of image analyst in this website. you will get
Accepted Answer
Image Analyst
on 18 Jan 2016
Easy. Threshold. Take the largest blob, then get its convex hull. See attached demo script below this image it creates:

7 Comments
Image Analyst
on 11 Apr 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?
More Answers (1)
Thorsten
on 18 Jan 2016
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!