1. Collect images of different types and show their properties using the imfinfo function of Scilab.
2. Open the previously acquired scanned image (I will be using a leaf) and convert it into grayscale if it is still colored.
3. Examine the histogram of the images. Convert them into black and white using im2bw. Choose the best threshold from the histogram.
4. Finally, apply the area calculation from last week to determine the area of the image.
____________________________________________________________________1. Binary Image
FileName: smith.gifFileSize: 1104
Format: GIF
Width: 244
Height: 153
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
source: http://www.sharewareplaza.com/Signature-Creator-download_31667.htmlFormat: GIF
Width: 244
Height: 153
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
2. Grayscale Image
FileName: xray.jpgFileSize: 4424
Format: JPEG
Width: 183
Height: 193
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000
source: http://www.answers.com/topic/x-ray?cat=health
3. Truecolor Image
FileName: butterfly.jpgFileSize: 14300
Format: JPEG
Width: 267
Height: 200
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000
source: http://monarch-butterfly.info
Here is the scanned image of a leaf I mentioned in last week's report and its properties.
FileName: leaf2.jpgFileSize: 2851
Format: JPEG
Width: 170
Height: 181
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000
It was converted into grayscale by using the following lines of code.
image = imread('leaf.jpg');
grayimage = im2gray(image);
imwrite(grayimage, 'leaf2.jpg');
Next, we create a histogram plot of the number of pixels falling under a specific grayscale value. A value of 0 corresponds to black while 255 is for white. The code for plotting the histogram and the resulting graph are shown below.
//original code c/o Jeric Tugaff
image = imread('leaf2.jpg');
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(image==i); //finds where image==i
val(counter)=i;
num(counter)=length(x); //find how many pixels of leaf have a value of i
counter=counter+1;
end
plot(val, num); //plot
From this histogram, we can see that there is a dip in the 100-180 region. We can now convert our grayscaled leaf image into black and white by using im2bw. Our threshold value can range from 0.4 to 0.7. I used 0.5 in this case. However, note that the parameters for the follow function (the function that follows the contour of the image) require that the object has a value of 1(white) and the background has a value of 0(black). This means that the colors of our current B&W image have to be inverted before we can calculate for its area. We can do this in Scilab by simple matrix manipulation: BWleaf = 1 - BWleaf; and again we write the resulting image into a file.BEFORE, AFTER, & AFTER STILL...



We can do the same for any other image. The procedure would be as follows:
- open the image
- convert to grayscale
- plot histogram
- convert to B&W using a suitable threshold value
- invert colors
Whew! After all of that, we are now ready to calculate for the area of the leaf using Green's theorem.
[x,y] = follow(BWleaf);
x_1(1) = x(length(x));
x_1(2:length(x)) = x(1:(length(x) - 1));
y_1(1) = y(length(y));
y_1(2:length(y)) = y(1:(length(y) - 1));
A = abs(1/2*(sum((x.*y_1) - (y.*x_1))));
theo = sum(BWleaf);
Upon comparing the values, we get theo = 7202 and A = 7000.5. This yields an error of only 2.8%. This error comes from the image of the leaf having some concavities. According to the other proof of Green's theorem (from A2 - Area estimation of images with defined edges.pdf),
I give myself 10 points for this activity since like last week, the error between the theoretical and calculated areas are less than 5%. Special thanks goes to Jeric Tugaff and Jorge Presto for the help in plotting the histogram of the grayscaled image.
[x,y] = follow(BWleaf);
x_1(1) = x(length(x));
x_1(2:length(x)) = x(1:(length(x) - 1));
y_1(1) = y(length(y));
y_1(2:length(y)) = y(1:(length(y) - 1));
A = abs(1/2*(sum((x.*y_1) - (y.*x_1))));
theo = sum(BWleaf);
Upon comparing the values, we get theo = 7202 and A = 7000.5. This yields an error of only 2.8%. This error comes from the image of the leaf having some concavities. According to the other proof of Green's theorem (from A2 - Area estimation of images with defined edges.pdf),
so long as a closed curve is convex (no concavities) its area may be computed by
summing the area of its “pie slices.”
____________________________________________________________________Thus, Green's theorem for estimating areas will not work all of the time. This may be why the error between calculated and theoretical area is large compared to the regular polygons' areas from last time.
I give myself 10 points for this activity since like last week, the error between the theoretical and calculated areas are less than 5%. Special thanks goes to Jeric Tugaff and Jorge Presto for the help in plotting the histogram of the grayscaled image.
0 comments:
Post a Comment