Thursday, July 17, 2008

Activity 9: Binary operations

In this activity, we aim to use what we have learned so far in finding the area of a piece of circular punched paper. This may seem easy but these many circles are scattered: some are touching or even on top of each other. We will therefore analyze several regions of interest in one image.

PROCEDURE:
1. If the image is large, divide it into several 256x256 sub-images so that less memory space is used. Another way is to just resize the image. Open the image in grayscale using im2gray or gray_imread.
2. Plot the histogram of the sub-image and determine its thresholding value. Binarize the image using im2bw.
3. Do morphological operations to remove isolated pixels, separate connected blobs or fill out holes. The opening and closing operations can do this "image cleaning." The opening operation is just an erosion followed by a dilation. On the other hand, the closing operation is a dilation followed by an erosion.
4. Use bwlabel to label each blob on the image.
5. Find the areas of each disk of punched paper. Repeat for the other sub-images and give the best estimate of the area.
____________________________________________________________________

The image used in this activity and one of its sub-images are shown below.

















After binarization and morphology (closing first then opening operations),














HISTOGRAM OF AREAS
From the histogram, it seems as if the correct value of the area lies between 500 and 600 pixels since the histogram bars are highest around these values. The values smaller than 500 are those disks that got cropped off when the sub-images were created or those that do not look like a circle anymore after the morphological operations. Values larger than 600 are those overlapping disks or those too close together that they got combined by the morphological operations. After removing these values, we get the mean and standard deviation. These tell us the best estimate for the area of an individual punched paper.

Mean area = 538 pixels
Standard deviation = 24.83

We need to verify if this value for the area is acceptable. We can do this by finding non-overlapping disks and then calculating the areas.

Mean area = 549 pixels
Standard deviation = 13.05

error for area = 2%

Also, the standard deviations are quite close. Smaller standard deviations indicate that the other areas are close to the mean value.





____________________________________________________________________

stacksize(4e7);

subimg = 11; //no. of sub images
c = 1;
for i = 1:subimg
im = gray_imread('c2_0'+string(i)+'.jpg');
im = im2bw(im, 0.85); //convert to BW with corresponding threshold value
//scf(0); imshow(im);

image = ones(5,5);
SE = mkfftfilter(image,'binary',2); //structuring element
im = dilate(im,SE); //closing operation
im = erode(im,SE);
im = erode(im,SE); //opening operation
im = dilate(im,SE);
//scf(i); imshow(im);

[L,n] = bwlabel(im); //label the individual blobs

//area calculation of individual blobs
for j = 1:n
roi = (L==j);
A(c) = sum(roi);
c = c + 1;
end
end

scf(12); histplot(length(A),A);
title('Histogram of disk areas');
xlabel('bins'); ylabel('frequency');

//remove too small and too large areas
range_area = find(A>500 & A<600);
mean_area = sum(A(range_area))/length(range_area); //mean area
std_area = stdev(A(range_area)); //standard deviation
____________________________________________________________________

I give myself 10 points for this activity since a good estimate of the area of the punched paper was given. Thanks to Jeric Tugaff for help in the histogram and in removing the unwanted small and big area values.

0 comments: