Binary

Format PNG
Width 200
Height 141
Depth 8
StorageType indexed
NumberOfColors 2
Resolution (0, 0) cm
Grayscale

Format PNG
Width 200
Height 141
Depth 8
StorageType indexed
NumberOfColors 256
Resolution (1.031D+09, 1.031D+09) cm
Truecolor

Format PNG
Width 200
Height 150
Depth 8
StorageType truecolor
NumberOfColors 0
ResolutionUnit (3.436D+08, 3.436D+08) cm
Indexed

Format PNG
Width 200
Height 150
Depth 8
StorageType indexed
NumberOfColors 256
ResolutionUnit (3.436D+08, 3.436D+08) cm
*Images were taken from: grow.ars-informatica.ca/images/grass_close-up.jpg & upload.wikimedia.org/wikipedia/commons/thumb/9/9f/Southport_Sunset.PNG/800px-Southport_Sunset.PNG
The next part of this activity is to measure an area of a flat object using images. The image used here was a scanned ID.(with rulers on the x and y axis)

Width 500
Height 306
Depth 8
StorageType indexed
NumberOfColors 256
Resolution (- 3.436D+08, - 3.436D+08) cm
(NOTE: the rulers in the image was cropped)
Using Scilab, the histogram of this grayscale image was obtained.

From this histogram, we can the that the region of interest(ROI) is mostly separated from the background. There are only a few pixels which are not close to the peaks. The threshold I used was the average of the 2 highest peaks (~230), because if I used the first highest peak(~205) as the threshold, there are still parts of the object which were not included. However, if the second highest peak was used ( ~255), some of the background was included in the object.

The area of the thresholded image was calculated using Green's theorem. The obtained area was 101656.5 sq. pixels. Using the rulers in the image(and by pixel counting), the conversion from pixel to mm was found to be 46pixels = 10mm. So 4.6x4.6 pixels = 21.16 sq.pixels = 1 sq. mm. Using this conversion and the value obtained from Green's theorem, the area of the ID was computed to be (101656.5/21.16)*1sq.mm = 4804.18 sq. mm. To see if this calculation was correct, I measured the dimensions of the ID and calculated its area. The area using this was 54mm*86mm = 4644 sq. mm. The calculated area using images have a 3.4% error compared to the area calculated physically.
For this activity, I give myself a grade of 10 since I performed the activity quite well and without help from others.
Scilab code for histogram and threshold:
pict = imread("idimage.bmp");
if max(pict) <= 1 //indexed, colored image
x = 1:256;
pict = im2gray(pict) * 255 + 1;
pict = round(pict);
else //indexed, grayscale
x = 1:256;
end
y = x.*0;
mat = size(pict);
for i = 1:mat(1)
for j = 1:mat(2)
y(pict(i, j)) = y(pict(i, j)) + 1;
end
end
bar(x, y)
//end of histogram
//thresholding
srt = sort(y);
for i = 1:256
if y(i) == max(y);
max_x = i;
elseif y(i) == srt(2)
max_x2 = i;
end
end
ave = (max_x + max_x2)/2;
thresh = round(ave);
for i = 1:mat(1)
for j = 1:mat(2)
if pict(i, j) <= thresh
pict(i, j) = 1;
else
pict(i, j) = 0;
end
end
end
imwrite(pict, "threshold.bmp");
No comments:
Post a Comment