Thursday, June 30, 2011

Activity 4 - Area estimation of images with defined edges

I wished I had realized all my mistakes from last night up to this lunch or early this afternoon. I will have the chance to code the follow command if I did not realized early this morning that I could get the follow function in SIP even without installing Scilab 4.1.2 or any version of this Scilab. I spent my time last night browsing for possibility in coding the function early today. I already downloaded the book that the guy wrote the code as his reference. I had a hard time in doing this for Scilab 5.3.2. But now, I have the follow function. If you are using Scilab 5.3.2, and want to get the follow function, click here!

Now it's time to write about the activity. If I have known that I can get the function even not installing the SIP and without using Scilab 4.1.2, I might have finished this activity since yesterday, 28 June 2011. But no, faith doesn't want me to finish earlier. But now, I am done.

First in the activity is to generate some figures. I have tried images of circles and squares. I want to try to generate a triangle using scilab but I felt lazy doing it. Even my circles and squares are not generated by scilab but I painted it. Anyway, under is an image of my code.

Fig. 1. My code
As you can observe, there is an additional command that I used in order to use the follow function. It's ok but it's kind of weird for me because I am now used to use my own functions placed in a folder in Matlab. But Scilab needs you to call all *.sci files in order to use them. I used the dots per inches of paint since I used paint to edit my images.

Fig. 2. Table of areas

The figure to the left is a table of my the area obtained using the Green's function and another way to compute the area which is the sum of the values of the matrix since its value is 1 per pixel so using the conversion from pixel to inches or cm then the area will simply be the sum of the pixel's values. This idea was a knowledge from high school.
Fig. 3. Circles used from 2 cm to 12 cm
Fig. 5. error plot for Sum and Green's function



The figure on the left is the image I used that increases in radius in order to differentiate the diversion of the area using Green's function and its true theoretical value. As you may observe the figure on the right above, the error decreases as the radius of the circle increases. With this, a circle with higher radius will be accurately calculated using Green's function. I think a good scale between the pixel and its real-world measurement.

Next, I look for something in google maps that interests me a lot and that is an ISLAND. Islands are so great and beautiful and there have facts in the internet that could say what is its land area. I like islands. I want to have my own island and make it a paradise. But first, I need to finish this.

Fig. 6. The feature I preferre
This island is called Cagbalete Island and it has white sands that can be seen during low tide. Most tourists stay south of the island and stay to the three known resorts in the area - the Villa Cleofas, Pansacola Beach Resort and MVT Sto. NiƱo Beach Resort. The islands land area is approx. 1,640 hectares or 16.40 sq. km.

Fig. 7. Binary image of the island
This is the BINARY image of the island. I first create an outline on the edge of the island then converted the new image into a binary image and edit it again until I get the figure to the left.

After that, I then computed the area of this figure using the sum function and the green's function. I found the ratio between the pixel size and the real-world measurement to be 0.019048. This is in pixel per km. I then calculated the Area using the sum method, and Green's function, 19.098088 sq. km with an error of approx. 15%  and 18.911 sq. km with an error of approx. 17%.

I have compared the real-world value and the simulated value. The error is big because I edit the data and may be the area becomes big.

Yes.. I am done. Not completely done but I am happy that I have completed this activity. In gradings, I will be giving myself as 11 with 5 points on both Technical and Qualities part and a 1 point for my initiative to use other programs in order to obtain the most critical error value.

Tuesday, June 28, 2011

Activity 3 - Image Types and Formats

Hello. Good day. I am a bit lazy these days. I don't know why but I am really lazy and I can't create a blog without these things that is coming out of my fingers as it pushed the keyboard this 23 June 2011. So here is my blog.

We have been asked to look for examples of image types, basic and advanced file types. It's a bit difficult in looking for these files because only truecolor or RGB are seen in the web. I just convert everything to have examples of each type. Below are the examples:

--------------------------------------------------------------------------------------------------------------

Fig. 1. Example of a Binary Image
The image at the left is an example of a BINARY image. I have seen this over the internet. As you can see below, the color type of this image is grayscale because in scilab 5.3.2, imfinfo only returns the strings 'true color' or 'grayscale' but the image is really a BINARY image. Below is the info of the file:
  • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - binary.jpg'
  • FileModDate: '23-Jun-2011 10:18:24'
  • FileSize: 15517
  • Format: 'jpg'
  • FormatVersion: ''
  • Width: 400
  • Height: 333
  • BitDepth: 8
  • ColorType: 'grayscale'
  • FormatSignature: ''
  • NumberOfSamples: 1
  • CodingMethod: 'Huffman'
  • CodingProcess: 'Sequential'
  • Comment: {}
---------------------------------------------------------------------------------------------------------------

Fig. 2. Example of a Grayscale image

To the right is an example of a GRAYSCALE image. Below is its file info:
  • FileModDate: '23-Jun-2011 10:21:47'
  • FileSize: 66496
  • Format: 'jpg'
  • FormatVersion: ''
  • Width: 400
  • Height: 329
  • BitDepth: 8
  • ColorType: 'grayscale'
  • FormatSignature: ''
  • NumberOfSamples: 1
  • CodingMethod: 'Huffman'
  • CodingProcess: 'Sequential'
  • Comment: {}
---------------------------------------------------------------------------------------------------------------
Fig. 3. Example of a True Color image

The image to the right is an example of a TRUE COLOR image. Below is the info of this image.
  • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - truecolor.png'
  • FileModDate: '21-Jun-2011 11:53:18'
  • FileSize: 86245
  • Format: 'jpg'
  • FormatVersion: ''
  • Width: 300
  • Height: 300
  • BitDepth: 24
  • ColorType: 'truecolor'
  • FormatSignature: ''
  • NumberOfSamples: 3
  • CodingMethod: 'Huffman'
  • CodingProcess: 'Sequential'
  • Comment: {[1x58 char]}
--------------------------------------------------------------------------------------------------------------
    Fig. 4. Example of an indexed image
    To the right is my example of an Indexed image. I don't know how I can show to you that this is an indexed image since SIVP cannot give an indexed image color type. I have converted this one from RGB to INDexed image. Below is the file info:
    • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - indexed.jpg'
    • FileModDate: '23-Jun-2011 10:39:41
    • FileSize: 27774
    • Format: 'jpg'
    • FormatVersion: ''
    • Width: 400
    • Height: 300
    • BitDepth: 24
    • ColorType: 'truecolor'
    • FormatSignature: ''
    • NumberOfSamples: 3
    • CodingMethod: 'Huffman'
    • CodingProcess: 'Sequential'
    • Comment: {}
    ------------------------------------------------------------------------------------
    Fig. 5. Example of HDR image
    The image to the right is an example of HDR image. Below is its info:
    •  Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - HDR.jpg'
    • FileModDate: '23-Jun-2011 11:31:41
    • FileSize: 53871
    • Format: 'jpg'
    • FormatVersion: ''
    • Width: 450
    • Height: 301
    • BitDepth: 24
    • ColorType: 'truecolor'
    • FormatSignature: ''
    • NumberOfSamples: 3
    • CodingMethod: 'Huffman'
    • CodingProcess: 'Progressive'
    • Comment: {}
    ---------------------------------------------------------------------------------------------------------------
    Fig. 6. Example of a Hyperspectral Image
    Next is the HYPERSPECTRAL file type. Below is the file:
    • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - Hyperspectral.jpg'
    • FileModDate: '23-Jun-2011 11:32:43'
    • FileSize: 28509
    • Format: 'jpg'
    • FormatVersion: ''
    • Width: 370
    • Height: 329
    • BitDepth: 24
    • ColorType: 'truecolor'
    • FormatSignature: ''
    • NumberOfSamples: 3
    • CodingMethod: 'Huffman'
    • CodingProcess: 'Sequential'
    • Comment: {}
    --------------------------------------------------------------------------------------------------------------
    Fig. 7. Example of a 3D image
    To the right is a 3D image file. Below is its file info:
    • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - 3D.jpg'
    • FileModDate: '23-Jun-2011 11:36:47'
    • FileSize: 2187543
    • Format: 'jpg'
    • FormatVersion: ''
    • Width: 1653
    • Height: 1050
    • BitDepth: 24
    • ColorType: 'truecolor'
    • FormatSignature: ''
    • NumberOfSamples: 3
    • CodingMethod: 'Huffman'
    • CodingProcess: 'Sequential'
    • Comment: {}
    • Orientation: 1
    • XResolution: 72
    • YResolution: 72
    • ResolutionUnit: 'Inch'
    • Software: 'Adobe Photoshop CS2 Windows '
    • DateTime: '2006:01:17 12:15:10 '
    • DigitalCamera: [1x1 struct]
    ---------------------------------------------------------------------------------------------------------------
    Here is an example of a video file. Below is its file info:
    • Filename: 'C:\Users\MP\Documents\Dropbox\Files\186\A3 - clock.avi'
    •  FileModDate: 'Saturday, June 18, 2011, 11:15:27 AM'
    • FileSize: '82944'
    • Format: 'avi'
    • Video
      • Length: 00:00:12
      • Frame width: 321
      • Frame height: 321
      • Data rate: 48 kbps
      • Total bit rate: 56 kbps
      • Frame rate: 1 frame/second
    • Audio
      • Bit rate: 8 kbps
      • Channel: 1(mono)
      • Audio sample rate: 8 kHz
    ---------------------------------------------------------------------------------------------------------------
    Fig. 8. Size of the scanned image
    As you can see to the right, based on the size of the scanned image from Activity 1, the scanned image is a true color image.
    ---------------------------------------------------------------------------------------------------------------
    Fig. 9. Histogram of the grayscaled scanned image

    The image above is the histogram of my scanned image from Activity 1. As I observed it, the minimum threshold for this image is around 0.3. I, then converted the grayscale image into black and white and used the threshold I have observe. Below is the image of the black and white image using the threshold.
    Fig. 10. Black and white Image using threshold = 0.3
    The image above has change clearly compared to its original image as seen in this blog, http://see-through-things.weebly.com/1/post/2011/06/activity-1.html The mostly gray part on the background was clearly removed and thus, clearly differentiate the lines and the background.
    ---------------------------------------------------------------------------------------------------------------
    Image File Formats
    • JPEG/JPG 
      •  JPEG is an acronym for Joint Photographic Experts Group which created the standard with the approval of ISO in 1992, 1994, 1996, 1998 and underdevelopment since 2009. Its typical usage is in photographs and realistic scenery. This type uses lossy compression but it has an option of lossless compression
    source: http://en.wikipedia.org/wiki/JPEG
      • BMP
        •  BMP stands for Bitmap Image File or simply Bitmap is a Raster graphics image file format that stores bitmap image files independent from the storing device. My source quote one paragraph from Microsoft  support:
      "A device-independent bitmap (DIB) is a format used to define device-independent bitmaps in various color resolutions. The main purpose of DIBs is to allow bitmaps to be moved from one device to another (hence, the device-independent part of the name). A DIB is an external format, in contrast to a device-dependent bitmap, which appears in the system as a bitmap object (created by an application...). A DIB is normally transported in metafiles (usually using the StretchDIBits() function), BMP files, and the Clipboard (CF_DIB data format)."

      for more info: http://en.wikipedia.org/wiki/BMP_file_format
      • PNG
        • PNG means Portable Network Graphics which is also a bitmap image format and video codec that utilizes lossless compression. This supports palette - based images, grayscale images and RGB images. It starts with an 8 - byte signature header followed by a "chunk" of files. After these files, there goes the color depth and transparency of image. After these, there is compression and filtering of the image. This offers an interlacing algorithm called Adam7 algorithm. PNG does not support animation but its file extension, MNG does.
      source: http://en.wikipedia.org/wiki/Portable_Network_Graphics
      • TIF/TIFF
        • This is the last type that I will discuss. TIFF stands for Tagged Image File Format which stores image and mainly popular to professional photographers. They say that this file type is a flexible, adaptable file type. This file type does not have any provision in compression and no restrictions. It was defined by ISO in 1993.
      source:http://en.wikipedia.org/wiki/TIF
      ---------------------------------------------------------------------------------------------------------------
        You may be thinking why I placed this part in here. It is just because I am just lazy to place this part in the middle of the blog. I am tired in doing this because histplot does not work in Scilab 5.3.2. I don't know why, it just didn't work. If it worked, I must be finished last thursday, but no. I had to run it in the computer of James Pang that uses Scilab 4.x.x. I thought I can finish it by that time and this coming Tuesday is the Activity 4. Hayyy. Oh well. That's life. And this is my blog. Thank you for having the time to read this.

        Oh I forgot something. I will rate myself  with 11 overall. Both Technical and Presentation Qualities are 5 each and 1 for the initiative because I have used SIVP in showing the other images and have incorporated my previous activity blog as a comparison to one of the figures above. :)

        Edited at 11:18 AM, 28 June 2011.
        I have found the command for histplot in Scilab 5.3.2. Here is the link. http://app186.blogspot.com/2011/06/histplot-in-scilab-532-using-sivp.html

        Histplot in Scilab 5.3.2 using SIVP

        I have found the command in determining the histogram of a grayscale image. It is imhist command in SIVP. This tutorial is for Scilab 5.3.2. I have copied the help from the scilab help.

        Name
        imhist - get the histogram of an image
        Calling Sequence
        [counts, cells] = imhist(im)
        [counts, cells] = imhist(im, bins)
        [counts, cells] = imhist(im, bins [,width [,color]])
        Parameters

        im
        An image, which can be a boolean, uint8, int8, uint16, int16, int32 or double image
        bins
        The number of bins of the histogram. If bins is not specified, the function will used default value which determined by the image type: 2 for boolean, 2^8 for uint8 and int8, 2^16 for uint16 and int16, 2^16 for int32(2^32 will need huge computer memory), and 10 for double.
        width
        This argument will be sent to the bar function. It is a real scalar, defines the width(a percentage of the available room) for the bar(default: 0.8,i.e. 80%)
        color
        This argument will be sent to bar function. It is a string(default: 'blue'), specifying the inside color bar.
        counts
        the returned histogram
        cells
        the intervals for bins
        ---------------------------------------------------------------------------------------------------------------
        So here it is. Just place it with the bar function to get a histogram figure.

        Transfer completed!

        Yey. I have completely transferred my two other activities from the other blog. I thought this transfer will take me too long to finish but no. haha

        Anyway, I have a difficulty encountered in Activity 4. I don't know the follow command in scilab. So, I am searching for it right now. I will be editing this one as I find the true meaning of follow command for scilab 5.3.2. Good luck to me.. :)

        Activity 2 - Scilab Basics

        I have posted this last 20/06/2011. Here is the link.http://see-through-things.weebly.com/1/post/2011/06/activity-2-scilab-basics.html

        Another activity has passed and here I am again saying to you about this. I have a few difficulty encountered as I do this activity but I conquered this difficulty and applied the basics of Scilab to gain points for this activity. The activity has 6 items to do. Below are the activities that were done for Activity 2.

        Here, I have placed a circular aperture on the center of the image. This part is a practice in order to familiarize the codes in using scilab. The code below is the code of this figure:
        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        r = sqrt(X.^2 + Y.^2);//note: element per element squaring of X and Y
        A = zeros(nx,ny); //creating a nx-by-ny matrix
        A(find(r<0.7)) = 1;
        imshow(A);
        imwrite(A, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Circles.jpg");
        The figure above is somewhat difficult for me. At first I did not understand how it can be created but after several trials, I have created figure 3. At first it was only one horizontal white rectangle in the middle. It made me think that maybe scilab has the &-property wherein both statement are true before the command will proceed. And with that, I have created a square aperture located in the center. Below is the code for the square aperture:
        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        A = zeros(nx, ny);
        A(find(abs(X) < 0.4 & abs(Y) < 0.4)) = 1;
        imshow(A);
        imwrite(A, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Square.jpg");
        I do not know whether the figure above is correct or not. I simply place a sine wave into the X - axis values and there it is. It just popped up like it is correct. I guess it is correct. Below is the code I have created for this figure.
        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        cr = sin(X * 6 * %pi) //%pi is 3.1415
        imshow(cr);
        imwrite(cr, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Sinusoid.jpg");
        This one is the easiest part that I have done. There is no instruction in how far should the spacing of this grating should be so I assumed to be one space after another. Below is the code I have written in making a grating.
        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        A = zeros(nx, ny);
        for i = 1:2:nx
            A(i,:) = 1;
        end
        imshow(A);
        imwrite(A, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Grating.jpg");
        This one is as simple as the practice part. Aside from looking for the indices of small value, I made a range of values of the circle so that an annulus is formed. This is like an absolute value, i.e. |x| < 1 ===> -1 < x < 1. Below is the code for the annulus.
        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        r = sqrt(X.^2 + Y.^2);//note: element per element squaring of X and Y
        A = zeros(nx,ny); //creating a nx-by-ny matrix
        A( find( r < 0.7 & r > 0.65 ) ) = 1;
        imshow(A);
        imwrite(A, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Annulus.jpg");

        I happened to know how to do this one since I am making one of this for my research. It is simply having a grid values X and Y then placing it into the equation for the Gaussian Distribution. Below is the code I have made.

        nx = 100; ny = 100; //defines the number of elements along x and y
        x = linspace(-1, 1, nx); //defines the range
        y = linspace (-1, 1, ny);
        [X, Y] = ndgrid(x,y); //creates two 2D arrays of x and y coordinates
        sigma = 0.4;
        r = 1/sqrt( 2 * %pi * sigma^2) * exp( -0.5 * ( X.^2 + Y.^2) / sigma^2); //Gaussian distribution
        imshow(r);
        imwrite(r, "C:\Users\MP\Documents\Dropbox\Files\186\A2 - Aperture.jpg");
        I have done this activity last Friday, 17 June 2011. I am not that in a hurry. It's just that I have a vacant time that I have nothing else to do. I will rate myself with 5 for technical corrections since I can see that I have done no error for this activity. Another 5 for Presentation quality because I have placed the figures with their captions and also the codes I have made in creating those figures. And for the Initiative part, I have given myself 2 points because I have used the formula of the Gaussian distribution and the logic & in getting the square in the middle.

        Activity 1 - Digital Scanning

        This is a copy of my previous blog in another website. I will transfer the other activity after this one. Thank you.
        Figure 1. Scanned hand-drawn plot in a 1970s thesis
        located in NIP Library.

        Here I am, writing a blog for my class. I don't why I have to do this but I have to do this blog right now. I am done in duplicating the graph I have. The image above is the one I have gotten from a thesis from 1970. The picture below is the graph I have attempted in duplicating the picture above.
           
            As you can see, the plot I have created with the red-colored line almost coincide with the graph that I have chosen. I have not duplicated the entire plot due to it's rotation that I have done with the help of James Christopher Pang and GIMP. :)

            It was difficult to do the approximations using only the PAINT program. It has features that was not there in order to rotate the image because the plot is not straight and so the pixel of a straight vertical line varies. After rotating the graph, it looks like a good graph already and so I superimpose the rotated image and the plot that I have and poof, the lines almost coincide.

            I am happy with what I have done. I am sure I have done a good job in doing the activity. So I guess, I will rate myself with 4 for the Technical Corrections because the figure I have has still some corrections and it's not exactly the same, 4 for Quality of Presentation because it has few errors in the figure, 2 for the Initiatives because I have used another software in order to have a more accurate figure to duplicate.

        Picture
        Figure 2. Duplicated plot with the red line as the duplicate line and the sample is the dark line.

        Thursday, June 23, 2011

        Transfer of blogs for AP 186

        I have transferred here in Blogger because I cannot upload any image at NIP. Here is the link from my former blog which will be transferred here after this activity was done. Thank you!