# Extract repeating structure from an image

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.

• Do you want to distinguish the wavy lines from the straight ones? Can they be interleaved; or are they always oriented as depicted?
– Emre
Jan 22, 2016 at 23:04

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.

1. 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]]

1. Detect the edges:

binImg = EdgeDetect[evenImg, 1, .1]

Now we just need to fill in the strokes:

smImg = ImageResize[Dilation[binImg, 2], {500}]

Show[smImg, Graphics[{Yellow, Thick, Line /@ ImageLines[smImg, 0.25]}]]

1. 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


• How can I do that command by using matlab? Show[smImg, Graphics[{Yellow, Thick, Line /@ ImageLines[smImg, 0.25]}]],Please help me Jan 23, 2016 at 17:39
• It's just for superposing the lines on the original images, so you'd probably use imfuse
– Emre
Jan 23, 2016 at 18:22
• Thanks.I am trying to implement the algorithm in matlab. Still struggling..Thank you. Jan 23, 2016 at 18:42
• The path to enlightenment is not without struggle :) Here are the relevant MATLAB functions.
– Emre
Jan 23, 2016 at 18:48