Question: *Edit: this is not a duplicate of [Determine if an image exists within a larger image, and if so, find it, using Python](https://stackoverflow.com/questions/29663764/determine-if-an-image-exists-within-a-larger-image-and-if-so-find-it-using-py) since **I do not know the pattern beforehand***

Suppose I have a big image (usually a picture taken with a camera so it might be a bit noisy, but let's assume it's not for now) made up of multiple smaller images all equal among themselves, something like

[![enter image description here](https://i.stack.imgur.com/0V2bB.png)](https://i.stack.imgur.com/0V2bB.png)

I need to find the contour of each one of those. The first step is recognizing that there's a recurring image (or unknown pattern) in the 2D image. How can I achieve this first step?

I did read around that I might use a FFT of the original image and search for duplicate frequencies, would that be a feasible approach?

To build a bit on the problem: I do not know the image beforehand, nor its size or how many will there be on the big image. The images can be shot from camera so they might be noisy. The images won't overlap.

Answer: 
For such a clean image, it suffices to segment the patterns by blob analysis and to compare the segments or ROI that contain them. The size is a first matching criterion. The SAD, SSD or correlation similarity scores can do finer comparison.

[![enter image description here](https://i.stack.imgur.com/nUZbJ.png)](https://i.stack.imgur.com/nUZbJ.png)

In practice you will face more difficulties such as

* not possible to segment the patterns
* geometric variations in size/orientation
* partial occlusion
* ...

Handling these is out of the scope of this answer; it makes things much harder than in the "toy" case.
The goal is to find several equal or very similar patterns which are not known before in a picture. As it is this problem is still a bit ill posed.

* Are the patterns exactly equal or only similar (added noise maybe)?
* Do you want to have the largest possible patterns or are smaller subpatterns okay too or are all possible patterns needed? Reason is that of course each pattern could consist of equal patterns too.
* Is the background always that simple (completely white) or can it be much more difficult? What do we know about it?
* Are the patterns always equally oriented, equally scaled, non-overlapping?

For the simple case of non-overlapping patterns with simple background, the answer of [Yves Daoust](https://stackoverflow.com/a/34311086/1536976) using segmentation is well performing but fails if patterns are very close or overlapping.

For other cases the idea of the keypoints by [Micka](https://stackoverflow.com/a/34314697/1536976) will help but might not perform well if there is noise or might be slow.

I have one alternative: look at correlations of subblocks of the image.

In pseudocode:

* Divide the image in overlapping areas of size MxN for a suitable M,N (pixel width and height chosen to be approximately the size of the desired pattern)
* Correlate each subblock with the whole image. Look for local maxima in the correlation. The position of these maxima denotes the position of similar regions.
* Choose a global threshold on all correlations (smartly somehow) and find sets of equal patterns.
* Determine the fine structure of these patterns by shanging the shape from rectangular (bounding box) to a more sophisticaed shape (maybe by looking at the shape of the peaks in the correlation)
* In case the approximate size of the desired patterns is not known before, try with large values of M, N and go down to smaller ones.
* To speed up the whole process start on a coarse scale (downscaled version of the image) and then process finer scales only where needed. Needs balancing of zooming in and performing correlations.

Sorry, I cannot make this a full Matlab project right now, but I hope this helps you.