Monday, June 22, 2009

A3 – Image types and basic image enhancement

Images
"An image is represented by a two-dimensional table in which each cell is a pixel. To represent an image by means of computer, it is thus enough to create a pixel table in which each cell contains a value. The value stored in a cell is coded on a certain number of bits which determine the colour or the intensity of the pixel, This is called the coding depth (or is sometimes also called the colour depth. "[http://en.kioskea.net/contents/video/affich.php3]


Using imfinfo(filename, 'verbose') in Scilab , one can determine the type of an image and also determine other file information.

1.Grayscale:
Pixel color depth: 8-bit color

Grayscale images are monochromatic and carries only intensity information composed exclusively of shades of gray that vary from black (lowest intensity) to white (highest intensity) equivalent to 2^4 intensities( 256) or 8 bits per sampled pixel.

Image source:http://en.wikipedia.org/wiki/Grayscale


-->imfinfo('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png','verbose')
FileName: C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png
FileSize: 29342
Format: PNG
Width: 150
Height: 200
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
******
On part 6. Bonus – If you can make a program in Scilab to compute and plot the
histogram of a grayscale image, you get 2 points bonus.


im=imread('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png'); // read image
im=im*255;
scf(0);
m=tabul(im,'i');


hx=m(:,1);
hy=m(:,2);
h=scf(0);

[px,py]=size(im);
npixel=px*py;

nx= hx/max(hx);
ny= hy/npixel;

ccy=cumsum(ny).*(1/max(cumsum(ny)));

subplot(321);
plot(nx,ny);
title('norm hist');
title('nxy');

subplot(322);
plot(nx,ccy);
title('nxccy');

xs2gif(0,'C:\Users\USA\Desktop\histograms2.gif');
****************
2. True color
Pixel color depth: 24-bit color (True Color)

These consist of at least 256 shades of red, green, and blue resulting to around 16,777,216 color variations.

-->imfinfo('C:\Users\USA\Desktop\scilab and 186\color pizza.png','verbose')
FileName: C:\Users\USA\Desktop\scilab and 186\color pizza.png
FileSize: 246909
Format: PNG
Width: 302
Height: 302
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: centimeter
XResolution: 23.230000
YResolution: 23.230000

3. Binary

These are two level images, wherein each pixel store only store two possible values, that is, either 0 or 1, black or white but any two color combination can be used.

Image source: http://en.wikipedia.org/wiki/File:Neighborhood_watch_bw.png



-->imfinfo('C:\Users\USA\Desktop\scilab and 186\binary.png','verbose')
FileName: C:\Users\USA\Desktop\scilab and 186\binary.png
FileSize: 2660
Format: PNG
Width: 200
Height: 140
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000

4. Indexed
Indexed images are made up of colors indexed by its position in the pallete or an array of color elements. The color information is not directly carried by the image pixel data.

Image source: http://en.wikipedia.org/wiki/File:IndexedColorSample_(Mosaic).png


-->imfinfo('C:\Users\USA\Desktop\indexed.png','verbose')
FileName: C:\Users\USA\Desktop\indexed.png
FileSize: 9789
Format: PNG
Width: 160
Height: 142
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000


********************************


Getting the area of scanned of images or objects
In this part, a rebisco cracker was photograph and the resulting image was scanned and the area of this biscuit was computed using the resulting plot in Scilab from the traced edges through the command follow.( Whahah I later realized that I should have scanned the rebisco directly in order to lessen the error :p .. oh well )

The procedure and results are as follows:
1. Take picture and scan it.
2. Approximate the physical area via an area of a circle with radius r=diameter/2.
3. Find the computed area from the ratio of the no. of pixels to the actual measurements in the photo or take the plot of the object via the follow() command.
4. The first one was difficult cause the x y coordinates in the photo matching the pixels in paint required alllot of data points and I soon give up this approach.
5. I then used the plot in the follow() command to trace the edges. and approximate the object as a circle and get the radius from the diameter.
6. Also I compared the results of the computed area from analytical sum and the Green's function but wasn't able to relate these values to the physical area. (whahaa)
7. The difference between the analytical area and are computed from green’s function is the error in this estimation. Taking that its area for a circle, the physical area is around 14.13 cm (d=4.5 cm) while the computed are is 10.6814 (w/ d=3.4 cm from the plot).
8. The area from the two physical and numerical methods do not coincide since area of the object was only approximated to that of a circle even thought the object is curved in the edges. The computed area of the image is more accurate since it has taken into account the curved edges but is affected by the distortion of the scanned image. The error is 24.42 image if we take the physical area to be more accurate while 32.30% for the computed area.
9. The sources of errors includes the distortion effect of the camera, lighting or background and the shades or shadow in the edges . These errors may have been avoided if the object was scanned directly (o_o) or photographed in a uniform background lighting to avoid unwanted shading in the edges.
Here are the pix:

The scanned picture:


The image after im2bw and thresholding, and converting the black to white and vv. to get the sum of the white area:

The plot:

.*.*.*.*.*.*.*.

Grade:

No comments:

Post a Comment