# texture matching between patches of an image

I have an image A which I have divided into 4 x 4 subband images. For a given patch P1 in image A, I need to find another patch P2 in the same image A which is most similar: have same texture.

Till now my appraoch is to create feature vectors Fi for all i patches and using Euclid's distance formula find out which patch's feature vector is closest to given patch P1's feature vector.

Currently I have added following features:

1. Mean & Standard Deviation of brightness (using L channel of LAB colorspace)
2. Mean & Standard Deviation of color values in A channel of LAB colorspace
3. Mean & Standard Deviation of color values in B channel of LAB colorspace

Although I am getting similar patches but I still think the matching can be improved if I incorporate more prominent features (which I'm unaware of).

Following are my queries:

1. I have a doubt whether this is a good way to compare color between two patches.

2. Please suggest some more good features which can be helpful to get a proper differentiation.

3. Although most of my images are proper but are there any restrictions/drawbacks with the approach if image is dark and/or noisy? If yes, is there a good alternative approach or feature(s)?

• Interesting question! Can you perhaps add an example of what the "unexpected" match is? What match are you getting? – Peter K. Sep 8 '15 at 13:15
• Unfortunately, I cannot upload any images due to some restrictions where I am working. But, the problem is the closest patch which I am getting is not correct. Even for 'red' colored textured patch, the patch getting matched is one which contains light background colors. – kunal18 Sep 8 '15 at 13:36
• @stalin you can always find a similar or simulated image which is closer to your original image. If you don't have one then create one & post it! It will be useful! – Balaji R Sep 9 '15 at 5:45
• How big are your feature vectors? Have you tried normalising them? – geometrikal Sep 9 '15 at 7:37
• Currently, I have only 3 features in each of the feature vector: std of brightness, std of color values in A channel and std of color values in B channel – kunal18 Sep 9 '15 at 7:39

The mean and standard deviation are two measurements of a distribution. Others you could also use are higher order moments like 'skewness' (how skewed the distribution is) and 'kurtosis' (how 'peaky' the distribution is).

However, what I would try is a histogram of the values for each of the channels. For example, if you used a histogram with 16 bins, you would get a feature vector with 48 values. The histogram bin values can be thought of as a descriptor of the distribution.

To account for changes in brightness, you need to introduce some illumination invariance. Already the LAB colour-space splits the image into luminance (L) and color (AB) channels. To achieve illumination invariance I would normalise the L channel histogram values using the norm of whatever measure you are using (in this case, euclidean distance, it would be the l2 norm). Normalising the A or B channels is probably not necessary. The normalisation accounts for any linear changes in luminance.

Depending on the images, you could also add vectors like:

• histogram of oriented gradients (HOG)
• histogram of connected components (make B/W then count how many pixels are white in the 8 connected neighbours)
• k-means clustering of LAB values to get k centre LAB values which you can compare to other images.

and so on.

• So, in my feature vector Fi for each patch i, I should have histogram for each color channel? And while comparing two patches, I must calculate distance between respective histograms using some distance like Chi-square? – kunal18 Sep 10 '15 at 7:05
• Yes, but you could just use euclidean distance – geometrikal Sep 10 '15 at 8:04
• Imagine you have a vector $\mathbf{a}$ and another vector that is a scaled version of $\mathbf{a}$, $\mathbf{b} = \lambda\mathbf{a}$. If you compared the two vectors with euclidian distance you would get some non-zero result. But what if you wanted to compare the two vectors without regard to their magnitude? To do this you would normalise them. en.wikipedia.org/wiki/Norm_(mathematics) The type of norm you use depends on the distance measure you are using. e.g. you dont normalise with the l1 norm (manhattan distance) if using an l2 distance measure (euclidean distance) – geometrikal Sep 10 '15 at 9:51
• Illumination is typically a linear increase in brightness. e.g. for an image $a(x,y)$, a brighter image might be $b(x,y) = \lambda a(x,y)$. So if you wanted to introduce illumination invariance for some measurement $\mathcal{O}$, then you must have $\mathcal{O}(a) = \mathcal{O}(b)$. – geometrikal Sep 10 '15 at 9:54
• With you images, just looking at the patches what features does your brain identify as being important to differentiate them? (The human brain is the worlds best image analysis system) – geometrikal Sep 11 '15 at 0:51

Regarding LAB, it is a good way if you are interested in the differences as humans perceive them.

About texture, I would suggest taking a look at some proprietary texture descriptors:

1. Gray level co-occurrence matrix.
2. Response to wavelets