How can i get clear straight line edge detection ? I have used following image and i have following edge detect image this is not clear ?
7 次查看(过去 30 天)
显示 更早的评论
How can i get clear straight line edge detection ? I have used following image and i have following edge detect image this is not clear ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152660/image.jpeg)
2 个评论
Walter Roberson
2015-12-15
Is the original the one below? If so, then you have the problem that the vertical edges are not straight lines.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180852/image.jpeg)
采纳的回答
harjeet singh
2015-12-15
may be this code will help you, or do i know what type of edges exactly you want?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172354/image.png)
clear all
close all
image=imread('b.jpg');
figure(1)
imshow(image)
drawnow
image_g=rgb2gray(image);
figure(2)
imshow(image_g)
drawnow
a = (lagmatrix(image_g',1))';
a(isnan(a))=0;
c=double(a)-double(image_g);
c=c>20;
figure(3)
imshow(c)
drawnow
c=bwareaopen(c,10);
figure(4)
imshow(c)
drawnow
6 个评论
Walter Roberson
2015-12-17
What is a "perfect straight line edge detection"? And why would you want to apply it to an image whose lines are curved like the above image?
更多回答(4 个)
harjeet singh
2015-12-17
hello selva till yet i worked with finding the lines which are area of interest, i have to work on theta to tilt than on right angle, that i will do next time till that have a look this code.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172369/image.bmp)
clear all
close all
clc
image=imread('b.jpg');
%//////////////////////////////////////////
image_g=rgb2gray(image);
figure(3)
imshow(image_g)
drawnow
a = (lagmatrix(image_g',1))';
a(isnan(a))=0;
c=double(a)-double(image_g);
c=c>20;
figure(4)
imshow(c)
drawnow
c=bwareaopen(c,30);
figure(5)
imshow(c)
drawnow
[m1,n1]=size(c);
for i=150:m1
[lab,num]=bwlabel(c(i,:));
a1(i,:)=[i num];
end
a1=sortrows(a1,2);
r_all=a1(end,1);
%/////////////////////////////////////////////
[lab,num]=bwlabel(c);
for i=1:num
[r,c]=find(lab==i);
[r1,c1]=find(r==r_all);
if(length(r1)>0)
a=length(r);
mat(i,:)=[i a];
end
end
mat=sortrows(mat,2);
mat=flipud(mat);
%///////////////////////////////////////////////
img_1(1:m1,1:n1)=0;
img_1=logical(img_1);
for i=1:length(mat)
[r,c]=find(lab==mat(i,1));
at=[r c];
[r1,c1]=find(r==min(r));
num_1=[1 at(r1(1),2)];
[r1,c1]=find(r==max(r));
num_2=[m1 at(r1(1),2)];
%//////////////////////////////////////////////
startp=num_1;
endp=num_2;
pts=2000;
m=atan((endp(2)-startp(2))/(endp(1)-startp(1))); %gradient
%
% x=m1/2+m1*cos(m*3.14/180)
% y=n1/2+m1*sin(m*3.14/180)
if (m==Inf || m==-Inf) %vertical line
xx(1:pts)=startp(1);
yy(1:pts)=linspace(startp(2),endp(2),pts);
elseif m==0 %horizontal line
xx(1:pts)=linspace(startp(1),endp(1),pts);
yy(1:pts)=startp(2);
else %if (endp(1)-startp(1))~=0
xx=linspace(startp(1),endp(1),pts);
yy=m*(xx-startp(1))+startp(2);
end
xx=round(xx);
yy=round(yy);
for j=1:length(xx)
if(xx(j)>0 && yy(j)>0 && xx(j)<m1 && yy(j)<n1)
img_1(xx(j),yy(j))=1;
end
end
figure(7)
imshow(img_1)
drawnow
%/////////////////////////////////////////////////////////////////
end
Image Analyst
2015-12-17
You might be able to use hough(), houghlines() or RANSAC. Look up ransac in the MATLAB help - I think there's a function estimateGeometricTransform() that uses it.
0 个评论
Selva Karna
2015-12-19
3 个评论
Image Analyst
2015-12-19
That image looks absolutely nothing like the one Walter posted above from your duplicate question. This one is virtually all black with just a single line. Personally I wouldn't even bother doing anything with the image you posted here in your so called "Answer". Actually this should not even be here since it's not an "Answer" to your original question posted at the very top of this page. You should have posted it as a comment (perhaps under Walter's comment), or as an edit to your original question.
Also, in your duplicate question, people have suggested improving your image capture situation since it's always better to start with a good image than with a bad one and then try to fix it up. I don't remember you responding to them. Can you improve your images? If not why not? Have you considered contacting a professional machine vision company, or a professional photographer to help you with that? It would make your task unbelievably easier.
And you've asked 72 questions but have only ever accepted one of them. Accepting a question gives the person who took the time to answer you "reputation points" so you might want to thank some of the people who have helped you in the past by accepting their answers. It's kind of the etiquette here in the forum, along with not asking duplicate questions of course.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!