Monday, June 27, 2011

Image Types and everything nice

Pictures. They're everywhere. They're a part of our everyday lives. We always want to take a picture of something that happened to us. If one didn't bring a camera with him, he'd say, 'I wish I could have taken a picture of that' & etc. Pictures are either
hard or soft copies of our memories, may it be happy or sad. It's a means of preserving something that has happened to us. It's also a means of expressing oneself, because sometimes, the words are not that good enough or the words are hard to say.With our technology today,different image types now exists. How are they different from each other? What's the difference? They're one and the same. They're still pictures.

They are pictures. But different kinds of pictures means different image types. There are four basic image types: binary images, grayscale images, truecolor images, and indexed images.

Binary images are the simplest images. They are either black or white. A pixel can have a value of either one (1) or zero (0). It has a matrix size of MxNx1. Images are saved in binary if you are only interested in the line shapes. Examples of binary images are document text, fingertips, etc.

FileSize: 2660 Format:
PNG Width: 200
Height: 140
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000


Grayscale images comes next. These images are black and white images. Each pixel can have a value between 0 (black) to 255 (white). These are the images back in the past. But, you can see many photographers taking pictures in grayscale. Maybe, because in some sense, looking at a picture in black and white, you can see more details and you can appreciate the picture more than the colored one. Also, there's a sense of specialty in them. It also has a matrix size of MxNx1.

FileSize: 29342
Format: PNG
Width: 150
Height: 200
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000





Truecolor images are the basic colored images. Theses are comprised of three channels or bands. each channel is an intensity of a primary light (red, green, and blue). Truecolor images can come form many different sources. One is a digital camera. a Truecolor image has a matrix size of MxNx3.

FileSize: 1155749
Format: JPEG
Width: 1600
Height: 1200
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: centimeter
XResolution: 100.000000
YResolution: 100.000000







Indexed images are images where colors are referenced to a color map index. Two sets of data are stored in an indexed image, the image and the color map.

Format: GIF FileSize: 10015 Width: 100 Height: 100 Depth: 8StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000



Now with the internet, and more advanced techniques and devices, there are also advanced image types. Some are: High dynamic range (HDR) images, Multi or hyperspectral image, 3D images, and Temporal images or videos.

High dynamic range (HDR) images. There are lost of scenes that require more than 8-bit grayscale recording in order to be very appreciated. According to wiki, HDR images are images that uses a set of techniques that allows a greater dynamic range between the lightest and darkest areas of an image than current standard digital imaging techniques or photographic methods.

FileSize: 384990
Format: JPEG
Height: 600
Width: 800
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 300.000000
YResolution: 300.000000








Hyperspectral Images are images that have more bands than 3 (for Red, Green and Blue). These images collects and processes data from across the EM spectrum (from wiki).
FileSize: 30398
Format: JPEG
Width: 311
Height: 311
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 128.000000
YResolution: 128.000000













3D images are images in the three dimensions.
FileSize: 1498967
Format: JPEG
Width: 2346
Height: 1760
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000








Temporal Images or Videos. Moving Pictures. Their digitization, compression and method of capture has advanced dramatically.

The figure I chose to convert to grayscale and black and white is shown below(first figure). Its properties are listed above(under the indexed image). Turning it into black and white, I used the function im2bw and threshold values of 0.7 and 1 (2nd and 3rd figures respectively). To convert to grayscale (4th figure), I used gray_imread.










This is the scanned copy of the graph that I used for activity 1
The grayscale of this image is shown below.

Using histplot, I examined the graylevel histogram of the grayscaled graph image. The histplot is shown below.
Now, we have to convert our grayscaled graph image to black and white, but at what threshold would it be? Since our image is a graph(filled w/ lines), we have to choose the threshold value w/ the least number of points. For example, for the histplot above, we should choose our best threshold value from 0.0 to 0.6 and not from 0.6 to 1 (since those are already points from the background). To show the difference of all the threshold values, I made a video showing all the output images at different threshold values.
The best threshold value I think would be between 0.4 and 0.5. So I think it’s 0.45(figure below).

Image compression may be lossy or lossless. Lossless compression is preferred for archival purposes and often for medical imaging, technical drawings, clip art, or comics. Lossy methods are especially suitable for natural images such as photographs in applications where minor (sometimes imperceptible) loss of fidelity is acceptable to achieve a substantial reduction in bit rate(from wiki).

JPEG (Joint Photographic Expert Group) is a commonly used method of lossy compression in digital photograhy(here). This is the most commonly used image file format. Another file format is the Bitmap Image file. This image file is a common output of the Windows Operating System. The BMP supports all the four image types. Another image file type is the tiff (Tagged Image File Format). This file format is used for storing images, popular among graphic artists, the publishing industry, and both amateur and professional photographers in general (here).

PNG(Portable Network Graphics) is a bitmapped image format and video codec that employs lossless data compression. PNG supports palette-based images (with palettes of 24-bit RGB or 32-bit RGBA colors), grayscale images (with or without alpha channel), and RGB[A] images (with or without alpha channel). PNG was designed for transferring images on the Internet, not for professional-quality print graphics, and therefore does not support non-RGB color spaces such as CMYK.(here).

GIF (Graphics Interchange Format) is a bitmap image format. GIF images are compressed using a lossless data compression technique to reduce the file size without degrading the visual quality.(here)

For this activity, I would give myself a grade of 9. Although Ia was able to do the activity successfully, I submitted a late report. I would like to thank Ma'am jing for the support and wonderful advises. Thank you.



Tuesday, June 21, 2011

Scilab 101: The Basics

Scilab. what is it? Scilab is a free, high level, scientific programming language which is an
acceptable substitute for Matlab. got that? no? find out more about scilab here. I first
encountered scilab 5.3.0 back in AP 185. So when we saw the activity 2 manual and read that scilab was needed, I thought 'oh yeah, got that installed already, all i need to install is the SIVP
(Scilab Video and Image Processing)' or so i thought. Downloading SIVP was easy, I downloaded the 0.5.3 version. Installing it however, is another story. I don't know how long I spend on trying to install sivp. argh, it was so frustrating. Then Kuya art and BA (love you guys) offered advises via twitter (I was 'sort of' ranting in twitter :D) on how to install sivp. after installing sivp successfully-ish, I tried to execute the example in the manual, creating a centered circle. I tried to copy-paste the code (see below) to scilab, unfortunately, everytime I execute it, it will always say that there's an error with 'imshow'. what?! so i restarted scilab again, same thing happened. after doing it for about 5times, i was so sleepy already that i decided to continue doing the activity the next day. Bad idea.

Figure 1. Code for the centered circle (from the manual)

The next day, class time. I was trying to run the circle code again. to no avail. argh. I realized my "successful" installation wasn't exactly successful (#@$@#%$). I decided then to uninstall scilab and install an older version, the one suggested in the manual. Scilab 4.1.2 with Signal and Image Processing (SIP) Toolbox instead of SIVP. OMG! it worked!!!EUREKA!! I don't know what I would have done if it hadn't work. The figure that came out is shown below.
Figure 2. Centered Circle.

Cool!:D so the next part of the activity was to create different figures: Centered square aperture, sinusoid along the x-direction (corrugated roof), grating along the x-direction, annulus, and a circular aperture with graded transparency (gaussian transparency). This figures will be shown below after the code that was used to create the iamges.

First, the centered square aperture. I just recycled the circle code. The code used for the
centered square aperture is shown below.
Figure 3. Centered Square aperture code.

And the result!:D ta-da!
Figure 4. Centered square aperture.

Next, was the sinusoid along the x-direction (corrugated roof). The circle code was also recycled. I revised the circle code in a way that instead of using an equation for a circle, I used a sinusoidal equation, in this case a sine function.
Figure 5. Sinusoid in the x-direction (corrugated roof).

The figure generated is shown below.
Figure 6. Generated sinusoid in the x-direction.

Next up, grating along the x-direction. This one was sort of difficult for me. I didn't know how I'd make a grating. After having help, finally figured out how to do it, I just hope it's right.
Figure 7. grating in the x-direction code.

This took a long time to generate a figure. There was a problem, since i restarted scilab again (as it was hanging T.T), i forgot to load the sip toolbox (boo). After realizing my mistake (with elo's teaching:D), the figure below was generated.
Figure 8. generated grating figure along x-direction.

Second to the last, annulus. I didn't know what this was. So I googled it, see here for an insight to annulus.:D Once again, the circle was recycled. This wasn't a big shock in this case. Since the
annulus more or less looked like a donut, revising the circle code was the best option. You just have to add another condition so that it would kind of generate a smaller circle within the circle code.
Figure 9. annulus code
Figure generated below. Donut-shaped ---> i'm hungry :))
Figure 10. the Annulus
Hmm, now that i think about it, it kind of looks like a target mat(?), hmmm... Moving on, The last figure. Circular aperture with graded transparency (gaussian transparency).. Say.. ?! Gaussian Function, look here. What I did was I just added a gaussian function into the code, w/ some other revisions.
Figure 11. Circular aperture w/ graded transparency (gaussian) code.
And finally, the figure. It looks a like a light at the end of a very long tunnel:D
Figure 12. Circular aperture w/ graded transparency (gaussian)

WOW. That was.. fulfilling (?). I've never done any work like this before. amazing. Hmm,, gotta practice then.:D I'd like to thank my classmates for the insights:D So, for this activity, I'd think I'd grade myself a 9. I did pretty good (I think), but I could have done better. Still. Need more practice for further improvement. I think I'll try and make other figures, haha playing around on scilab in my spare time:D Till next time :)

Thursday, June 16, 2011

The Middle and the End(?)

The first activity in our AP 186 class is Digital Scanning. We had to find an old journal and look for an obviously hand-drawn graph. I found my hand-drawn graph in the graduate thesis manuscript entitled “Relaxation Times and the Initial Conditions of the One-Dimensional Fokker-Planck Equation” by Mr. Josefino Z. Villanueva dated September 1973.

The activity's objective was to use ratio and proportion to find the numerical values of a digitally scanned hand-drawn plot. I used paint and excel/spreadsheet for this activity.

First, I needed to scan a photocopy of the hand-drawn plot (figure 1). Using paint, I had to get the equivalent pixel values of the tick marks of the x- and y-axes. Then use ratio and proportion to get the equivalent “real” values of the pixel values. The graph's origin (0,0) has pixel values of 395,1673. Below are the pixel values of the tick marks of the X-axis (table 1) and Y-axis (table 2).

Figure 1. Scanned picture of the hand-drawn plot.

Table 1. Equivalent pixel values of the X-axis of the graph

Table 2. Equivalent pixel values of the Y-axis of the graph

Next, I moved my mouse over points in the graph to take down the pixel values of the points. Listed in table 3 are the data points that I have chosen.

Table 3. Pixel values of data points chosen from the graph.

Using the data in table 1, I plot the physical values of the tick marks of the x-axis versus the equivalent x-axis pixel values. This is shown in figure 2.

Figure 2. tick mark versus pixel values for x-axis

And also using the data in table 2, I plot the physical values of the tick marks of the x-axis versus the equivalent x-axis pixel values. This is shown in figure 3. This is for me to be able to get the best-fit line.
Figure 3. tick mark versus pixel values for Y-axis

After all of that, using the equations in the best-fit line for the x and the y, I just input the pixel value(f(x)), so that I'll get the true physical value of the points(x). I then plot the values that I have calculated and plot them with the original figure superimposed (Figure 4)

Figure 4. Plot of the calculated physical values superimposed with the scanned figure.

Before I used the best-fit line (as per suggestion of Ma'am Jing), I originally used the average for the ratio and proportion part. The values that I obtained were plotted and is shown in figure 5.

Figure 5. Plot of the calculated values w/ scanned figure superimposed (using average pixel values)


Comparing figure 4 and 5, you can see that figure 4 (using the best fit line) has a higher R-squared than that of figure 5 (using the average pixel values). And so Ma'am Jing was right.

From my results, I think I would have done a better job. Maybe taking more data points would have made the new figure have a higher R-squared.

And so, for this activity, I'd grade myself an 8/10. As much as I want to say that I did the work on my own, that's not entirely true. Krista helped me understand what I should be doing, because I was kind of lost from the start. And (I don't know why) I didn't quite understand the instructions. Anyway, after asking help form Krista, I finally understood the activity and was able to finish it.

This is my first time using paint as a source of gathering data. Never thought it could be used that way. I only use it to copy pictures, etc. It only shows how much I need to learn. And so, I'm looking forward to learning more new stuff. :)

Wednesday, June 15, 2011

First post (after how many months): the beginning

On our first meeting in our AP 186 class (Instrumentation Physics II), we were asked to look for a very old journal and look for an obviously hand-drawn graph. My classmates and I went to the CS Library to look for an old journal, unfortunately the library was being renovated and the old journals were already tied up and they can't be accessed anymore. So our only resort was the NIP library.

After we returned from the CS library, I went to the NIP library and started looking for an old journal. The librarian told me that the journals were not yet arranged by year and that it will be hard for me to look for a certain journal. Still, I browsed through the titles of the books, and started looking for a very old one.

Unfortunately, the oldest that I found was in the year 1994. It was a book of abstracts for the 4th World Physics Congress (I think). From the browsing, I saw a "hand-drawn" graph, and I figured that if I didn't find other better graphs, I would use it.

On the other side of the shelves, thesis manuscripts were filed, undergraduate and graduate. the thesis were arranged by year, and there was a note on the side saying the year the thesis was made. Under the undergraduate section, the oldest one was for the year 1990-ish, not that old. So I ventured on to the graduate section, and there on the top shelf, with only about 5 books, was for the years 1950-1989 (I think).

So I went through all the 5 books and started looking for graphs. In the first book, there wasn't any hand-drawn plots. So I look at the other books. Finally, I found one w/ about 9 plots under the appendix section. The thesis was dated September 1973. The book is way older than me. :|

Anyway, I found 9 plots. I figured my classmates won't be able to find another book, so I thought that I'll photocopy the other figures for them. My ID wasn't countersigned yet, so the librarian asked someone (maybe from the CS library) if I could photocopy parts of a thesis manuscript. Fortunately, I was allowed to borrow the book for a few minutes to be able to photocopy the figures. Unfortunately, the NIP library didn't have any copier machine. So i photocopied the figures in our printer sa org (UPPA, thanks!). Then I scanned all the figures at home. And I had my digitally scanned hand-drawn plots for the first activity.

:D