Activity 3: Image Types and Basic Image Enhancement

June 24, 2008 at 10:30 am (Uncategorized) (, , , , )

Image Types

True Color Image

//www.flickr.com/photos/8700785@N08/643095209/

from: http://www.flickr.com/photos/8700785@N08/643095209/

FileName: truecolor.jpg
FileSize: 189687
Format: JPEG
Width: 500
Height: 493
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000

Indexed Images.

indexed images parrot

from: http://en.wikipedia.org/wiki/Image:Adaptative_8bits_palette_sample_image.png

FileName: indexed.png
FileSize: 25576
Format: PNG
Width: 150
Height: 200
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000

Grayscale Image.

This is obtained by getting images from the web. However, this image is still 24 bits (which is not a property of grayscale images). To convert it to 8 bit (which is true grayscale), use the code:

im=imread(‘grayscale.jpg’);
im=im(:,:,1);
imwrite(im(:,:), ‘gs.jpg’);

//blog.paranoidferret.com/files/Tutorials/CSharp/Grayscale/bw_flower.jpg

from: http://blog.paranoidferret.com/files/Tutorials/CSharp/Grayscale/bw_flower.jpg

FileName: gs.jpg
FileSize: 9217
Format: JPEG
Width: 250
Height: 250
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000

Histogram and Thresholding

The histogram of the grayscale image was obtained using the following code:

//Jeric Tugaff
//Histogram

im=imread(‘grayscale.jpg’); //opens a 24 bit image
im=im(:,:,1);
imwrite(im(:,:), ‘gs.jpg’); //converts to 8 bit grayscale image
im=imread(‘gs.jpg’);
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(im==i); //finds where im==i
val(counter)=i;
num(counter)=length(x); //find how many pixels of im have value of i
counter=counter+1;
end
plot(val, num); //plot. 🙂

We obtained this plot of the histogram for the image of a grayscale flower:

Grayscale image histogram

The two peaks in the histogram plot is a hint that the image is of high quality, and is good for tresholding. To do the thresholding, we use the code:

im=imread(‘gs.jpg’);
thresh=140;
im=im2bw(im, thresh/255);
imshow(im);

This results to this binary image:

Binary Image

Application To Getting Area of Images

tresholds

The images show the effect of tresholding to the leaf image. The name of the image corresponds to the treshold. We can see that the most appriate is using threshold value of 200/255. The method done in using the area follows from the previous exercise. For this activity, the area is  20108.5 while the theoretical area is  20505 with error of 1.9%.

//Jeric Tugaff
//Getting image areas through green’s theorem and grayscale image tresholding

im=imread(‘leaf_cropped.JPG’);
im=im2gray(im); //convert to grayscale
im=im2bw(im, 200/255);
im=1*(im==0); //inverts the image
[x,y]=follow(im);
x1=[];
x1(1:length(x)-1)=x(2:length(x));
x1(length(x))=x(1);
y1=[];
y1(1:length(y)-1)=y(2:length(y));
y1(length(y))=y(1);
area=0.5*abs(sum(x1.*y-y1.*x))  //green’s theorem
ta=0;
[sx, sy]=size(im);    //finds the area through recatangles
for i=1:sy
f=find(im(:, i)==1);
ta=ta+max(f)-min(f);
end
ta
err=(area-ta)/ta*100
//[r,s]=imhist(‘leaf_cropped.JPG’);

Permalink Leave a Comment