Finding outer and inner edge of an ear image

I am using MATLAB 2013a. I used lot of edge detector techniques to find out both the edges, but I am able to find only outer edge.If anyone can help me with the code to find both the edges that will be great help for my work. The final image after finding edges resembles the attached image. Reply as soon as possible. Thank you.

1 Commento

Now I am able to detect outer as well as inner edge using attached code. Now what I am trying to do is I want to draw a line passing though 2 extreme endpoints(ymax,ymin) of outer edge(refer "rdgedetected.jpg"). Is there any direct function to do so or I have to do it by scanning each pixel and using Index value(=1) of it?? I don't have any idea about using for loop to scan pixel values in matlab. Thanks in adv
y=imread('C:\Users\Sukhada\Desktop\2.jpg');
imshow(y);
gy=rgb2gray(y);
figure,imshow(gy);
et=edge(gy,'canny',.305);
figure,imshow(et);

Accedi per commentare.

 Risposta accettata

Image Analyst
Image Analyst il 19 Mar 2016
Regarding your new question about finding the "extreme endpoints", do you mean the two points that are farthest away from each other, or do you mean the actual endpoints of the line, which may not necessarily be the two points farthest from each other?
To find the two points farthest from each other, regardless if they're endpoints of a line/curve or somewhere in the middle of the curve, just so a nested for loop. Don't worry - it will be fast. See attached demo.
If you mean the endpoints of the curves only, then you need to get them using bwmorph(binaryImage, 'endpoints') and use the Pythagorean Theorem on all pairs of points.

10 Commenti

Sukhada Vengurlekar
Sukhada Vengurlekar il 20 Mar 2016
Modificato: Sukhada Vengurlekar il 20 Mar 2016
I need to find farthest points(endpoints of m1- plz check attached image). To elaborate more, while scanning image row-wise the first column where RGB=[1,1,1] or INDEX=1 from top and bottom too. Actually I wanted to take highlighted points and their corresponding angles with maxline as shown in attached image and save them in an array. please check if you can help me. Thanks.
Yes, the m-file I attached in my last comment can do that. It seems that you have not even tried it or run it or tried to adapt it. When you do, you will see if finds the longest axis, and then finds where the cross axis crosses the contour. You just need to do that but at several points instead of the crossbar only at the center point of the long axis. I know you can do it because you're a brilliant engineer. If you still need help, attach just the left image, without all the annotation, and your modifications of my code.
Thank you for your help. I am now able to find maxline by using attached code. But the problem is It detects all the edges and draws perpendicular lines for all other edges.
when I run the code once, which includes following lines
%determine connected components
CC = bwconncomp(binaryImage,8);
%compute the area of each component
S = regionprops(CC,'Area');
%remove small objects
L = labelmatrix(CC);
binaryImage = ismember(L, find([S.Area] >= maxDistance ));
I could detect the maxline and only one perpendicular line as desired.
So can you tell me where should I insert the above lines so that I can get desired output?? Or should I replace them with other lines of code?
Sukhada, that's because you have lots of regions. You forgot to merge them all into one region with bwconvhull(). Fixed code is attached.
But the problem is I want inner edges too. I wanted to store angles made by inner pixels with respect to max line as shown in figure. How can I do this?
Once you find the longest line, then use the original edge image, not the convex hull image, to determine where the line hits a white pixel. Just follow what I did, but instead of just going out from the half way point, you'll do it at several different evenly spaced locations along the line. It's not hard so I'm sure you can adapt it. Again, follow what I did - just do it a bunch of times on the edge image.
yes working fine.. Thank you so much for your help :)
Sorry to bother you again but I am unable to draw parallel lines from evenly spaced points.. Can you help me??
I think the example I gave should be enough help. You should be able to modify it. All you need to do is to find the points - try linspace() - and use the same method I used for drawing a line through that point. It's just the point slope formula you learned in high school.
I could draw lines but not getting the meaning of following line which I adapted from your code.
line([1, columns], [y1, y2], 'color', 'w', 'LineWidth', 1);
Because I have to use it to find intersection points of perpendicular lines and edge of the ear. What exactly the bwboundaries() returns?? I searched a lot but ended with introduction of lot of errors while running the code. So can you suggest any helping function which will work fine with my requirement and can give me desired output? (code files are attached)

Accedi per commentare.

Più risposte (3)

Ahmet Cecen
Ahmet Cecen il 8 Mar 2016
A cheap trick would be to use bwconncomp on your edge image, and then use a for loop to only keeps the ones that contain a pixel with an element that has the maximum or minimum observed coordinate of edge pixels possible. That will give you the outermost shell in all cases except in the case where your outer edge happens to be slightly connected from a point to your inner edge.
You can fill it and call bwperim():
binaryImage = imfill(edgeImage, 'holes');
outerPerimeter = bwperim(binaryImage);
I tried following code.. but only able to get outer edge as shown in attached figure.
I = imread('C:\Users\Sukhada\Desktop\a1.jpg'); t1=graythresh(I); k1=im2bw(I,t1); k1=~k1; se = strel('disk',1); k0=imfill(~k1,'holes'); % new cc = bwconncomp(k0); % new k0(cc.PixelIdxList{1})=0; % new k1 = imfill(k1,'holes'); cellMask = k1 | k0; % new cellContours = bwperim(cellMask); % new cellContours2 = edge(cellMask,'canny',[],sqrt(2)); % new k1=~k1; bw = edge(k1,'canny',[],sqrt(2)); figure,imshow(bw); title('original') figure,imshow(cellContours); title('new, bwperim()') figure,imshow(cellContours2); title('new, edge()')
But I want both the outer and inner edges.. Can anyone correct the mistakes?? I want output as shown in "output" image.

5 Commenti

That's because this contour is not a closed contour. It's open at the sides of the image, unlike the image you originally posted. So it can't be filled.
Oh, and please read this.
Sorry for shabby writing.
marjan mome
marjan mome il 21 Apr 2016
Modificato: marjan mome il 21 Apr 2016
hi Thank for these codes .it is use full for me.but i want to find location of line cut outer edge .like this image.please help me .Reply as soon as possible. Thank you.
I'm doing a job and I'm having the same problem, did you solve it?
Why are you working on this? Who wants to know about ears? Is it some kind of biometric application? What's the "use case"? Just curious.
What kind of image are you starting with? You forgot to post it.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by