# Edge detection of a noisy rim

Posted 9 years ago
5775 Views
|
7 Replies
|
9 Total Likes
|
 I want to detect the edge of the glass lens in the image. The final result I want is one pixel edge along the lens I tried canny, sobel. The best result so far i get is attached. But I am kind stuck to detect the outer edge of the lens because of the noise. is there any idea about what I can do next? Or if there is any better edge detection method? I know there may be "normal cut"? Thank you Attachments:
7 Replies
Sort By:
Posted 9 years ago
 Dear Henrik,that looks like a really great solution, much better than mine. I tried it out and got a different result when I use your command:This was because I imported the file by "pulling it from the post". If I get it into Mathematica using Import I get what you report. That is curious because in both cases the image has the same resolution, i.e. ImageDimensions gives the same, namely {1311, 976}. Also the different result does not seem to depend on the parameter of EdgeDetect. Anyway, your solution is much nicer than mine.Cheers,Marco
Posted 9 years ago
 Dear Marco,it is nice that you like my "solution", I basically don't do anything - it is more a demonstration of the ability of Mathematica. And still the original problem is not solved: To recognice the border of lenses in a whole series of similar but different pictures. A slight variation - as you just found out (a really strange effect!) - ruins everything. I think an enhancement of the contrast (e.g. with ImageAdjust[img, 2]) might help a little.Ciao Henrik
Posted 9 years ago
 This problem is so interesting that I try a "solution" as well.Let "img" be the original image. Then the trick can be done by: imgLens = Thinning@Binarize@ DeleteBorderComponents@ SelectComponents[Blur@EdgeDetect[img, 4], "EnclosingComponentCount", # == 0 &] which gives: I am not really satisfied with this method, because it depends quite sensitive on the parameter of EdgeDetect. From this one can easily extract the coordinates of the boundary of the lens: imgDims = ImageDimensions[imgLens]; pts = {#2, imgDims[[1]] - #1 + 1} & @@@ Position[ImageData@imgLens, 1, {2}]; Graphics[{Blue, PointSize[.004], Point[pts]}, Axes -> True, Frame -> True] Ciao Henrik
Posted 9 years ago
 Wow. That is really neat result. So the processing includes? 1. Edge detect 2. blur3. DeleteBorderComponents? 4. Binarize 5. Thinning
Posted 9 years ago
 Yes, first comes the edge detection (which is quite sensible), then I blur a little (an attempt to have a closed contour), then I can apply SelectComponents[ ... ,"EnclosingComponentCount", # == 0 &] which actually does the work by selecting the outermost closed contour. (If this contour is not closed one gets the next closed one, the result then is the picture in Marco's last post.) The original picture has a very sharp edge on its left side, therefore DeleteBorderComponents is necessary. Finally Binarize to get {0 or 1} and Thinning to make the contourline "slim".Ciao Henrik
Posted 9 years ago
 Thank you very much.
Posted 9 years ago
 Hi,this is far from being efficient, it uses too many image processing commands and could hardly be less elegant. But it does find the edge - more or less. ImageMultiply[img, ColorNegate@ EdgeDetect[ WatershedComponents@ Binarize@ ImageMultiply[img, Sharpen[Erosion[ Dilation[ MeanFilter[ SelectComponents[ SelectComponents[ SelectComponents[(MorphologicalComponents[ BottomHatTransform[ GradientFilter[ DeleteSmallComponents@(MorphologicalComponents[ img, 0.562] // Colorize), 1.64], DiskMatrix[6]], Method -> "Connected"]), Large], "Count", -3], "Count", 1] // Colorize, 6], 6], 7] // ImageAdjust, 10]] // Colorize]] I called the image just img. Here's the result:Cheers,Marco
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.