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 ?

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

Is the original the one below? If so, then you have the problem that the vertical edges are not straight lines.

댓글을 달려면 로그인하십시오.

 채택된 답변

may be this code will help you, or do i know what type of edges exactly you want?
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

Thank you so much sir. but i Need clear straight line edge detection ?
selva, what do you mean by "clear straight line edge detection"?
selva, first of all try to reduce the white light coming from one direction which is destroying the edges, than you may try to reduce the number of colors using k-means.
Thank you sir .... I will apply ... can i known about k-means ? its a algorithm or inbuilt commend please refer me sir?
Walter Roberson sir . I Need perfect straight line edge detection sir.. can you help me sir?
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개)

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

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?
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
Thank you sir. and thank your spent time for me[GOLD time] but ... some other image did not clear output sir? so i have attached that image ? help me sir?
This code dose not give straight line edge in some one more image ? how improve get good performance ?so help me sir harjeet singh . I have attached that image ?

댓글을 달려면 로그인하십시오.

Thank you sir .... I will apply ... can i known about k-means ? its a algorithm or inbuilt commend please refer me sir?
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.
<<
>> I have attached one more image . this image not give clear straight line corrresponding image object count ,, so how to improve help me sir........

댓글 수: 3

selva please upload atleast 10 images of the same so that i do make changes in the code to run on all images
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

질문:

2015년 12월 15일

댓글:

2015년 12월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by