Saturday, August 25, 2012

9th Activity: Applications of Morphological Operations 2 of 3: Playing Notes by Image Processing

     I was so surprised when I learned that Scilab could actually play notes! So before doing what was actually tasked to us, I first explored this function by playing some songs. :)  I have had piano lessons when I was a kid. I also had violin lessons at the Conservatory of Music. Aaaaand I love to sing. :) So as you could see, I really love music. So when asked to choose for a music sheet, I couldn't decide what to actually use after being familiar to lots of it.

     Going back to the real thing, I chose the first piece that I was able to play when I was a kid. It was entitled "Ode to Joy." The first line is shown in Figure 1.

Figure 1. First line of Ode to Joy
     I then inverted it and removed the g-clef as shown in Figure 2.

Figure 2. Inverted image
    Using the function imcorrcoef, the image is being compared to another image which is referred to as a template. I made a quarter note and a half note as templates as shown in Figure 3.

 

Figure 3. Templates to be used
  
     Thresholding was done after taking the result of the correlation. This was done to obtain a single pixel location for the quarter notes and half notes. These are shown in Figure 4 and Figure 5.



Figure 4. Locations of quarter notes

Figure 5. Location of half note


     Now that the locations of the notes are determined, the melody can now be played by assigning the frequencies for each note and then using the sound function. The sound file can now played below.



Reference
[1]Maricor Soriano. 2012. Activity 9 - Applications of Morphological Operations 2 of 3 - Playing Notes by Image Processing. Applied Physics 186

8th Activity: Applications of Morphological Operations1 of 3: Preprocessing Text

A scanned document was given to us as shown in Figure 1. Using the different morphological operations learned previously, handwritten texts will be extracted. 

Figure 1. Scanned document

     A part of the scanned document was scanned. Since the image was slightly tilted, it was corrected using GIMP. This correction is necessary for further steps to be done. The cropped image was converted to grayscale. These are shown Figure 2. 
 Figure 2. Cropped image and its grayscale format

     To remove the horizontal lines, a filter was applied. The Fourier transform of the image was first obtained. The filter was done by blocking the high frequencies in the Fourier transform.The FT of the image was then multiplied to the filter. Figure 3 shows the Fourier transform and the filter that was made (using GIMP).



Figure 3. Fourier transform of the cropped image and the filter used


    The resulting image is shown in Figure 4. It can be seen that the horizontal lines are now removed. However, the lines that intersected with the letters were also removed. Thus, the letters seems to be cut into half. :( Figure 5 shows the binarized image.

Figure 4. The resulting filtered image
   
Figure 5. Binarized image
     Dilation was applied to the image where the structuring element is a diagonal. I chose a diagonal as a structuring element to connect the letters since the handwriting is somewhat diagonally written. :) Figure 6 shows the resulting dilation.
Figure 6. Dilated image
     Since the image has become thicker, skel  was utilized to make it thinner. Figure 7 shows the resulting image.
Figure 7. Skeletonized(thinned) image

     It can be seen that some of the letter can be easily read now. :)


Reference:

[1] . Maricor Soriano, "A8 - Applications of Morphological Operations 1 of 3: Preprocessing Text", Applied Physics 186 Manual, 2012


Self-evaluation:
I admit I submitted this later due to SPP and my own research and experiments, but I would still give myself a 10. I was able to produce the necessary output and I was able to use concepts learned from previous activities.



Thursday, August 2, 2012

7th Activity: Morphological Operations

This activity is about some morphological operations: erosion and dilation. We were tasked to hand-draw the effect of erosion and dilation on particular images. Predicted sketches were compared to the generated image from erode( ) and dilate( ) functions in Scilab. 

Erosion of an image A by structuring element B is denoted by 
where B is the translation of B by z. The structuring element dictates the shape of the original image. It generally shrinks the size of the image. 


On the other hand, dilation is denoted by 
.
Dilation increases the shape of the original image according to the structuring element. 


To see the effects of erosion and dilation, different shapes were drawn and eroded by different structuring elements. Figure 1 shows the shapes that were drawn while Figure 2 shows the structuring elements used for each shape. 
Figure 1. Shapes to be eroded: square, triangle, hollow square, and plus sign


 Figure 2. Structuring elements: 2x2 ones, 2x1 ones, 1x2 ones, cross, diagonal 



Figure 3. Predicted effect of erosion(1st row) and dilation(2nd row) on a square



Figure 4.  Predicted effect of erosion(1st row) and dilation(2nd row) on a triangle 



Figure 5.  Predicted effect of erosion(1st row) and dilation(2nd row) on a hollow square 


Figure 6.  Predicted effect of erosion(1st row) and dilation(2nd row) on a plus sign 

     Lastly, the predicted images were compared to the output images generated by Scilab. Fortunately, the SIP toolbox has the functions erode( ) and dilate( ). It was quite easy then. Figure 7 to Figure 10 displays the output images when the shapes in Figure 1 were eroded and dilated by the structuring elements seen in Figure 2. 


Figure 7. Output images when square was eroded(1st row)
and dilated(2nd row) by the structuring elements
  

Figure 8. Output images when triangle was eroded(1st row)
and dilated(2nd row) by the structuring elements 

 
Figure 9. Output image when a hollow square was eroded(1st row)
and dilated(2nd row) by the structuring elements

Figure 10. Output image when plus sign was eroded(1st row)
and dilated(2nd row) by the structuring elements 
     
     It can be clearly seen that the predicted images matched the output images generated from Scilab. 

Reference:
[1] Soriano, M. A7 - Morphological Operations. 2012


Self-evaluation:

I will give myself a grade of 10/10 for understanding the concept of erosion and dilation. I was also able to present all the necessary output clearly.