Showing posts with label vertical lines. Show all posts
Showing posts with label vertical lines. Show all posts

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.



Wednesday, April 22, 2015

2D FFT: Effects of Location & Thickness of Vertical Lines on 2D FFT Magnitude & Phase: Part 03


Problem
  
This post continues our series of posts on a programmatic investigation of the effects of the location and thickness of horizontal, vertical, and diagonal lines on the magnitude and phase components of 2D FFT. In this post, we will continue our investigation of vertical lines by modifying their location in the image without modifying their thickness. The MATLAB source of our programmatic investigation is in the last section of this post. The previous post on vertical lines is here.

Vertical Line Shifted Right



Figure 1 shows a line shifted right in the image.

Figure 1. Vertical line shifted right in the image (hor_line_01c.jpg)
We add the path, read the image, and display it. 
 
addpath C:\Users\Vladimir\research\images\
ImgVerLine_01c = imread('ver_line_01c', 'jpg');

figure;
imshow(ImgVerLine_01c);
title('VER LINE 01c');

 
Now we compute the 2D FFT of the image in Figure 1. The image is converted into a 2D double matrix. The fftshift command positions the 0,0 origin to the center of the image. We compute the absolute magnitude of each value in the 2D matrix and take the log of each value. 1 is added to each value before taking the log, because log(0) is not defined.
 
%%% ff2 magnitude
fftVerLine01c = fft2(double(ImgVerLine_01c));
fftVerLine01c = fftshift(fftVerLine01c);
fftVerLine01c = abs(fftVerLine01c);
fftVerLine01c = log(fftVerLine01c+1);
fftVerLine01c = mat2gray(fftVerLine01c);


The magnitude image is shown in Figure 2. As can be seen in Figure 2, the FFT magnitude shows a line orthogonal to the vertical line in Figure 1. Note that with horizontal lines the 2D FFT magnitude lines are vertical.

figure;
imshow(fftVerLine01c);
colormap(gray);
title('VER LINE 01c FFT2 Magnitude');

Figure 2. 2D FFT magnitude of Figure 1
 We compute the phase component and display it. The image is shown in Figure 3.

%%% fft2 phase
fftVerLine01c_PHASE = fft2(double(ImgVerLine_01c));
fftVerLine01c_PHASE = fftshift(fftVerLine01c_PHASE);
fftVerLine01c_PHASE = angle(fftVerLine01c_PHASE);

figure;
imshow(fftVerLine01c_PHASE, [-pi, pi]), colormap(gray);
title('VER LINE 01c FFT2 Phase');
Figure 3. 2D FFT phase of Figure 1
The MATLAB source is at the end of this post.