Image Types
1. Truecolor Image
*photographed by Kate Dado
FileName: truecolor.jpg
FileSize: 35662
Format: JPEG
Width: 300
Height: 400
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000
2. Grayscale Image
*http://www.jnevins.com/Angelwebgrayscale.jpg
FileName: grayscale.jpg
FileSize: 47925
Format: JPEG
Width: 378
Height: 504
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000
3. Indexed Image
*http://imgtops.sourceforge.net/bakeoff/o-png8.png
FileName: indexed.png
FileSize: 139332
Format: PNG
Width: 400
Height: 400
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
4. Binary Image
Shown below is a truecolor image of a flower.
*photographed by Kate Dado
To obtain a binary image from this truecolor image, I first converted it to grayscale using the following code.
im=imread('flower.jpg');
im=im(:,:,1);
imwrite(im,'flower_gs.jpg');
I then examined the histogram of flower_gs.jpg using...
(a) GIMP
and
(b) SciLab Histogram Plotting Code (© Jeric Tugaff)
im=imread('flower_gs.jpg');
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(im==i);
val(counter)=i;
num(counter)=length(x);
counter=counter+1;
end
plot(val, num);
From the histogram, we see that there are two significant clusters of pixel values, one on the black side (0) and one on the white side (255). Therefore, we can choose a value for thresholding the image to separate the background from the region of interest (ROI), by simply examining the image histogram. Then we incorporate this threshold value to convert flower_gs.jpg to binary.
thresh=150;
im=im2bw(im,thresh/255);
FileName: binary.gif
FileSize: 19608
Format: GIF
Width: 400
Height: 300
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
Thresholding and Area Calculation Part 2
Thresholding is done by examining the histogram of an image, as detailed above. Shown is a scanned image of a leaf.
im=imread('leaf.jpg');
For purposes, which I'll explain later, I cropped the image.**
im=imread('cropleaf.jpg');
This is a truecolor image, and so, I first converted it to grayscale to obtain its histogram.
im=imread('cropleaf_gs.jpg');
Two peaks are evident on the histogram, a hint that the image is of good quality, and that we can separate the leaf from the background. We then again find a threshold to be used for converting the image into binary.
thresh=175;
im=im2bw(im,thresh/255);
To calculate the area of the leaf, using Green's theorem (see this), we first incorporate the following code.
im=1-im;
Effectively, this inverts the pixel values such that the area bounded by the contour of the leaf would be 1's (white) and those outside are 0's (black). This is important since what we are going to calculate the area of the leaf, not the area outside the leaf (or the background).
Using Green's theorem, the area calculated is 21466.5 pixels.
Comparing this with the area calculated using pixel counting* which is 21967 pixels, we see a 2.28% difference between them.
*ImageArea=sum(im);
//summing can be done since we know that the value inside the contour of the leaf are all 1's and that outside are 0's, and therefore summing the whole image will just result to the area (in pixels) of the leaf.
**The image of the leaf was cropped so that the ruler won't be included in the area calculation.
---
Thanks to...
Jeric Tugaff for the histogram plotting code. :)
---
Rating: 10/10
since a 2.28% difference between the two methods for area calculation is within the 5% acceptable limit.
Tuesday, June 24, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment