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 commentaires

check demos of image analyst in this website. you will get
Walter Roberson
Walter Roberson le 18 Jan 2016
imclearborder() ?

Connectez-vous pour commenter.

 Réponse acceptée

Image Analyst
Image Analyst le 18 Jan 2016

0 votes

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

7 commentaires

huijie Q
huijie Q le 23 Jan 2016
I still cannot get it. Should I delete my program first or need to add your program in?
huijie Q
huijie Q le 23 Jan 2016
I cannot get the final masked and the masked image.
Image Analyst
Image Analyst le 23 Jan 2016
Why not? You can turn my code into a function called GetMaskedImage() or something. What went wrong?
huijie Q
huijie Q le 25 Jan 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 le 25 Jan 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 le 11 Avr 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 le 11 Avr 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?

Connectez-vous pour commenter.

Plus de réponses (1)

Thorsten
Thorsten le 18 Jan 2016

0 votes

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

Community Treasure Hunt

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

Start Hunting!

Translated by