## Saturday, July 30, 2016

### On 2D Ordered HWT Coefficients of Horizontal and Vertical Lines

Problem

Suppose that an image has horizontal or vertical lines. What happens when a 2D ordered Haar Wavelet Transform (HWT) applied to it? For the sake of clarity and simplicity, let us assume that an image contains only 1 horizontal or vertical line at different locations. The second simplifying assumption is that an image is n x n where n is an integral power of 2. This is a requirement for 2D HWT. If the size of the image is not n x n, the image can typically be reduced or padded. The third simplifying assumption is that the thickness of a line is equal to exactly 1 pixel.  In my next post, I plan to do an investigation of diagonal lines.

Horizontal Lines

Fig. 1 is a synthetic 8x8 grayscale image with a horizontal line on top at row 0. Fig. 2 is a pixel value matrix of the image in Fig. 1.

 Figure 1. 8x8 Image with a horizontal line at row 0
 Figure 2. Pixel value matrix of image in Fig. 1

Fig. 3 is a matrix of 2D ordered HWT coefficients after 1 iteration applied to the matrix in Fig. 2. The corresponding average and vertical coefficients of each 2x2 block are highlighted with yellow when they are significantly greater than 0. These significant vertical changes are detected in blocks 0, 1, 2, and 3, i.e., exactly between rows 0 and 1 in the pixel value matrix in Fig. 2. Since the real values of the vertical coefficients are greater than 0, they signify a negative drop in data, i.e., from 255 to 0.

 Figure 3. 2D Ordered HWT coefficients after 1 iteration

Let us now place a line at an odd row. Fig. 4 is a 8x8 image with a horizontal line at row 5. Fig. 5 is the corresponding matrix of grayscale pixel values.

 Figure 4. 8x8 grayscale image with a horizontal line at row 5
 Figure 5. Pixel value matrix of the image in Fig. 4
 Figure 6. 2D ordered HWT coefficients of the matrix in Fig. 5 after 1 iteration
Fig. 6 is a matrix of the 2D ordered HWT coefficients after 1 iteration of the 2D ordered HWT applied to the matrix in Fig. 5. The corresponding average and vertical coefficients of each 2x2 block are marked with yellow when they are significantly greater than 0. These significant vertical changes are detected in blocks 8, 9, 10, and 11, i.e., exactly between rows 4 and 5 in the pixel value matrix in Fig. 5. Since the real values of the vertical coefficients are less than 0, they signify a positive increase in the underlying 2D data, i.e., from 0 in row 4 to 255 in row 5.

Vertical Lines

Let us take a look at vertical lines. Fig. 7 is an 8x8 grayscale image with a vertical line at column 2. Fig. 8 is the pixel value matrix of the image in Fig. 7.

 Figure 7. 8x8 grayscale image with a line at column 2

 Figure 8. Pixel value matrix of the image in Fig. 7
The coefficients obtained from applying the 2D ordered HWT to the matrix in Fig. 8 are in Fig. 9. The highlighted coefficients indicate that the significant changes in blocks 1, 5, 9, and 13, i.e., between columns 2 and 3. However, this time, since the line is vertical, the vertical coefficients in these blocks are 0 whereas the horizontal coefficients are significantly greater than 0 due to a negative drop in the underlying data, i.e., from 255 in column 2 to 0 in column 3.

 Figure 9. 2D ordered HWT coefficients of the matrix in Fig. 8
Let us now place a vertical line at an odd column. Fig. 10 is an 8x8 image with a vertical line at column 5. Fig. 11 is the pixel value matrix of the image in Fig. 10.

 Figure 10. 8x8 grayscale image with a vertical line at column 5
 Figure 11. Pixel value matrix of the image in Fig. 10

Figure 12 is the matrix of the 2D ordered HWT coefficients after 1 iteration on the matrix in Fig. 11. The significant horizontal changes are detected in blocks 2, 6, 10, 14, i.e., between column 4 to column 5. Since the horizontal coefficients are negative, there is a rise in the underlying data values, i.e., from 0 in column 4 up to 255 in column 5.

 Figure 12. 2D ordered HWT coefficients after 1 iteration on the matrix in Fig. 11

Conclusions

Horizontal lines are characterized by significant vertical changes and zero (or close to it) horizontal coefficients. When a horizontal line is placed at an even row, the vertical coefficients are positive, which signifies a negative drop in the underlying data values. When a horizontal line is placed at an odd row, the vertical coefficients are negative, which signifies a rise in the underlying data values.

Vertical lines are characterized by  significant horizontal changes and zero vertical changes. When a vertical line is placed at an even column, the horizontal coefficients are positive, which signifies a negative drop in the underlying data values. When a vertical line is placed at an odd column, the horizontal coefficients are negative, which indicates a rise in the underlying data values.