I want to find repeating structures from the image .But I have no idea how to do it.Please help me.Actually i want to find how many lines and oval shapes look like similar and mark these by separate color.
1 Answer
You want to detect two things: lines/curves and circles. There are well-known algorithms to do both, so let's find them separately. I will present a solution in Mathematica. You can translate to your language.
- The first step is to eliminate the background. We do this by finding the background:
img = Import["https://i.stack.imgur.com/Olczj.jpg"] bimg = ColorConvert[img, "Grayscale"] Blur[Closing[bimg, 20], 15]
Then dividing by it:
evenImg = Image[ImageData@bimg/ImageData@Blur[Closing[bimg, 20], 10]]
- Detect the edges:
binImg = EdgeDetect[evenImg, 1, .1]
Now we just need to fill in the strokes:
smImg = ImageResize[Dilation[binImg, 2], {500}]
- We are finally ready for some detection. Let's start with the lines/curves:
Show[smImg, Graphics[{Yellow, Thick, Line /@ ImageLines[smImg, 0.25]}]]
- What about the circles? Let's start by looking at all the connected components:
morph = MorphologicalComponents@smImg; Colorize@morph
The circles are there, all right. We just need to filter out the objects that are not circular. We can do this by looking at the circularity, elongation, eccentricity, or Euler characteristic. Circles are easy to distinguish from other shapes by these properties.
noncircles = #[[1]] & /@ ComponentMeasurements[morph, "Elongation", # > 0.3 &]
circles = morph /. x_ :> 0 /; MemberQ[noncircles, x] //
Colorize // RemoveBackground
-
$\begingroup$ How can I do that command by using matlab? Show[smImg, Graphics[{Yellow, Thick, Line /@ ImageLines[smImg, 0.25]}]],Please help me $\endgroup$– rossyJan 23, 2016 at 17:39
-
-
$\begingroup$ Thanks.I am trying to implement the algorithm in matlab. Still struggling..Thank you. $\endgroup$– rossyJan 23, 2016 at 18:42
-