Showing posts with label A. Show all posts
Showing posts with label A. Show all posts

Tuesday, September 6, 2011

XII

Preprocessing text is one real-world application for the image processing techniques that we have previously learned. For this activity, I have binarized handwritten text and performed template matching to find words within the document.

Figure 1. Original image

Figure 2. Region of Interest

Figure 3. 2D Fourier Transform of Fig. 2


Figure 4. Filtered Fourier Transform of Fig. 3

Figs. 2-3 show my attempt in removing the lines from the image. Due to the low resolution and noise of the original image, filtering in the frequency domain did not fully remove the line in the image. For me to continue to the binarization of the text, I manually removed the remaining gray-ish parts.

To facilitate the binarization, morphological transformation was implemented through the close and skel operations.

Figure 4. After operating close

Figure 5.  After operating skel() on Fig. 4

Fig. 5 shows the final preprocessed image. The "M" and "O" cannot be identified properly, but the "D", "E" and the "III" are still good. The quality of binarization is of course dependent on the quality of the original handwritten text. Due to the thinning strokes, the letters "M" and "O" were damaged by the processing.


Figure 6. Template

To end this, I finally do template correlation. Using imcorrcoef(), I tried to find other instances of the word "DESCRIPTION" in the image (Fig. 1). However, I was only able to find the same spot where my template came from.

Figure 7. imcorrcoef() result. 

Fig. 7 shows the result. Notice the white dot in the right side. This is the approximated location of the match of the used template from imcorrcoef().


  Self-Assessment: 7/10   


Saturday, July 30, 2011

IX

Morphological operations uses Set Theory to manipulate matrices. Since we now know that images are just matrices of values with layers of channels, it is appropriate that certain algorithms can be devised to do morphological operations with pictures.

This activity deals primarily with some basic shape alteration and recognition. For basic operations, binary "flattened" versions of multi-chanelled images are used. To start off, let's examine how these 2 operations work.

Note: Since the images are in their binary form, zeros are considered as background while ones are the object. Background is ignored by the operations, and is thus useful since the operations would only work if the matrices compared have the same dimensions.

First, matrix A (one containing the original pattern) is scanned with another matrix B (one containing the mask). Then, a new zero matrix C (transformed image) with the same dimensions as matrix A & B are mapped depending on the operation used:


  • erosion: All coordinates of the anchor point for when the mask is entirely enclosed by the object is set to one in matrix C. 

Figure 1. Erosion. The anchor point is the center of matrix B.


  • dilation: All coordinates of the anchor point for when at least one element of the mask intersects with the object is set to one.

Figure 2. Dilation. The anchor point is the center of matrix B.

Thus, the anchor element of the mask in matrix B determines how the transformed image will be shifted in matrix C with respect to matrix A.

Using 4 original patterns and 5 maskserosion and dilation are employed and their effects were observed. The anchor points for the masks are as follows:
  1. 2x2 square: Top-left pixel
  2. 2x1: Top pixel
  3. 1x3: Left pixel
  4. 3x3 cross: Top-most pixel 


                          Figure 3. Original Patterns: 5x5 square, 3x4 right triangle, 10x10 square annulus 2 pixels thick, 5x5 cross 
                                          Mask: 2x2 square, 2x1 , 1x2, 3x3 cross and a 2 pixel long diagonal.



erode()

Figure 4. My hand drawn predictions for erosion.


Figure 5. scilab's erode() operator results.


My prediction would've been perfect if not for my careless error on the diagonal mask of the square annulus. However, I now fully understand how erosion works. Since erosion "trims" by fitting the mask entirely, it is possible to have completely blank images. We can see this with the cross mask for the 3x4 triangle and the 2x2 mask for the 5x5 cross patterns.

dilate()
Figure 6. My hand drawn predictions for erosion.

Figure 7. scilab's dilate() operator results.

Again, like with my erosion predictions, this would've been perfect if not for the 1x2 mask of the square annulus.


thin() & skel()

Lastly, I examine the thin() and skel() operators of scilab. These are more complex than the erode() and dilate() operators. From the help file, the implementation of thin() on an image of text produces:

Figure 8. Above: Original image. Below: thin() results

thin() seems to trace lines and curves by "thinning" them until they are only one pixel wide. The deviations from straight lines came as a consequence of not using a perfectly binary image. The above image was just converted using im2bw(), in which the conversion led to some unstraightened lines when thin() was used.

As we can see, this may be problematic when we have lots of line nodes in our image. For this, we use the more complex skel(). 

Figure 9. L-R: Original image, result of skel() superimposed with the original and the distance transform.

skel() successfully traced a quite rounded and thick image. These characteristics would have resulted to a poor trace, had we used thin() for the image. skel()  seems to average the whole network of lines and deduce the "skeletal" frame of the image. As such, it also has a distance mapping output. This seems to be a pixel population distribution map of the image with respect to skel()'s traced path.

This was a good introductory activity for morphological transforms of images.


  Self-Assessment: 9/10   

Wednesday, June 15, 2011

I

Activity 1 - Digital Scanning

Using ratio and proportion, I have replicated Onnes' remarkable graph that gave birth to superconductivity.
Figure 1. Superconductivity of mercury [Source
  
Using Photoshop Elements, I have obtained the coordinates of the grid lines and obtained the best-fit lines to find a correlation equation between the pixels and the physical values it represents.
 Figure 2. Pixel conversion. Note the axes offsets. I have normalized the origin to (0,0)

 Figure 3. Axes' best-fit lines

From these equations, I have replicated the 6 data points of the original graph. With these, I have obtained the corresponding slopes per division, corresponding to: Normal, Transition and Superconducting (SC) states of the graph.



Figure 4. Linear fitting of the various regions. Normal state is the region with a linear resistance (T>~4.22K), Transition state is the region of greatest resistance change (dashed lines) and the Superconducting state is the region of very low resistance (T<4.2K)

I had problems with the SC region. This is due to the constant in the line equation, which means that my line can have negative values. Rethinking, I have abandoned the use of the line equation and placed a value of zero for temperatures lower than 4.2K in my graph. This decision came from thinking that realistically speaking, resistance values approaches zero for superconductors. The line equation gave erroneous data points at this region due to the limited amount of original data points that I have used to obtain it. Had the original graph been log scaled, this would've been clearer as the actual resolution of the graph is limited by pen and paper.

Figure 5. Overlay of the simulated graph(blue, step size=0.01) with the original graph image (black + points)

The final result is considerably good as we can see from Fig. 5. The Normal state deviation can be attributed to the regression of the line fit. Also, the Transition state is clearly exact due to the fact that it contains only 2 points at that region. Onnes' graph is a very simple scatter plot, as such, I have used linear fit lines to add more points for my replication. 

Simple but quite arduous.
Self-Assessment: 10/10