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 ?
Mostrar comentarios más antiguos
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 ?

2 comentarios
Walter Roberson
el 15 de Dic. de 2015
Please post the original as well.
Walter Roberson
el 15 de Dic. de 2015
Is the original the one below? If so, then you have the problem that the vertical edges are not straight lines.

Respuesta aceptada
Más respuestas (4)
harjeet singh
el 17 de Dic. de 2015
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.

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
4 comentarios
Image Analyst
el 17 de Dic. de 2015
I couldn't run it:
To use 'lagmatrix', you might need:
lagmatrix - Econometrics Toolbox
Error in test (line 13)
a = (lagmatrix(image_g',1))';
It doesn't seem like the Econometrix Toolbox should be required for an image processing app. Can you make it run without that toolbox?
harjeet singh
el 18 de Dic. de 2015
hello sir, use this code without lagmatrix i am still working on the theta to produce exact angle as it is in original image.
clear all
close all
clc
image=imread('b.jpg');
%//////////////////////////////////////////
image_g=rgb2gray(image);
figure(3)
imshow(image_g)
drawnow
dummy(1:size(image_g,1),1)=0;
a=[dummy image_g(:,1:end-1)];
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
Selva Karna
el 19 de Dic. de 2015
Selva Karna
el 19 de Dic. de 2015
Selva Karna
el 17 de Dic. de 2015
0 votos
Image Analyst
el 17 de Dic. de 2015
0 votos
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.
Selva Karna
el 19 de Dic. de 2015
0 votos
3 comentarios
harjeet singh
el 19 de Dic. de 2015
selva please upload atleast 10 images of the same so that i do make changes in the code to run on all images
Image Analyst
el 19 de Dic. de 2015
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.
Selva Karna
el 21 de Dic. de 2015
Categorías
Más información sobre Image Processing and Computer Vision en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

