# Using difference of average for identifying features in an image

I'm working with this paper: Textural Features Corresponding to Visual Perception, by Tamura, Mori, and Yamawaki. There's a part where you have to calculate neighborhoods of one image (matrix of, for example $256 \times 256$) and those neighborhoods have to be $2^k$ size square.

Step 1: Take averages at every point over neighborhoods whose sizes are powers of two, e.g., $1\times1$, $2\times2$, $\cdots$, $32\times32$. The average over the neighborhood of size $2^k\times2^k$ at the point $(x,y)$ is $$A_k(x,y)=\sum_{i=x-2^{k-1}}^{x+2^{k-1}-1}\sum_{j=y-2^{k-1}}^{y+2^{k-1}-1}f(i,j)\big/2^{2k}$$ where $f(i,j)$ is the gray-level at $(x,y)$.

Ok that's great.

Then I have to calculate a difference:

Step 2: For each point, at each point, take differences between pairs of averages corresponding to pairs of non-overlapping neighborhoods just on opposite sides of the point in both horizontal and vertical orientations. For examples, the difference in the horizontal case is $$E_{k,h}(x,y)=\left|A_k\left(x+2^{k-1},y\right)-A_k\left(x-2^{k-1},y\right)\right|.$$

Let $A(0,0)$ be the point where I want to calculate the difference.

If I use $A(0,0)$, I will go out of bounds on the second member.

Do you think it's an error? There's nothing about the '$h$' parameter anywhere as well.

$k$ could be $0, 1, 2 \dots$

• Perhaps it's h for horizontal. When you do differences, there will be an edge, of width $2^{k-1}$ where you can't do it exactly. – Empy2 Sep 12 '14 at 18:35

As Michael suggested, $h$ is for horizontal. You'll also have vertical difference $$E_{k,v}(x,y) = |A_k(x+2^{k-1},y) - A_k(x-2^{k-1},y)|$$ I think that they take $E_k = \max(E_{k,h},E_{k,v})$ and then maximize over $k$.

I will go out of bounds on the second member.

Yes you will, if $(x,y)$ are close to the boundary. The authors admit as much:

boundary strips of a picture within the width of the largest operator size $2L$ cannot be processed properly.

They offer no remedy to the boundary effects. One possible solution is to extend the image to a larger square by setting the color of every exterior pixel equal to the color of the image pixel nearest to it.

• It's a good answer, thanks. But I don't understand yet, if I take neighborhoods of k = 3, how to calculate the E1,h or E2,h or v... how could I do it ? – Rafael Ruiz Muñoz Sep 12 '14 at 19:04
• First you calculate $A_k$. Can you do that? – user147263 Sep 12 '14 at 19:05
• of course. Then ? – Rafael Ruiz Muñoz Sep 12 '14 at 19:06
• Then you subtract and take absolute value. I don't see what the trouble is. – user147263 Sep 12 '14 at 19:06
• The trouble are those variables (h and v)... what should I do with them ? – Rafael Ruiz Muñoz Sep 12 '14 at 19:10

It looks ok to me.

In the diagram I have taken $(x,y)$ to be $(5,4)$, so I am comparing two squares, one yellow, one orange, either side of $(x,y)$. That is the $k$ case. Then there is a similar comparison for the $h$ case. Of course, you run into trouble if you are too close to the border, but that is inevitable.