We tried to get the best estimate of the area of a punched paper by statistical analysis of a set of punched papers. We cut the image into six sub-images such as the one in figure 1 and converted them into grayscale. We looked at the histogram of their intensity values and determined that the threshold value should be set at intensity = 200.
We then performed the Morphological operations of opening and closing of holes to see what would happen. Opening of holes means to dilate with a structuring element L the image eroded with L. Closing of holes means to erode with the reflection of L the image dilated by the reflection of L. It seems that closing of holes had a better effect of producing a cleaner binary image. So I chose to continue processing this.
As shown in figure 3, the closed regions were labeled with a specific number. The area of each labeled region is determined by pixel counting.
The histogram of the above sample is merged with the histograms of other subimages. The result is the histogram shown above. It seemed that the histogram needed no further noise eradication. The best estimate for the area was 549 px.
To check, we get the number of included pixels in a binarized image of a single punched paper. It was 519. The deviation of the best estimate from this value was around 6%.
Code:
for i = 1:7;
//1 Call image, transform it to black-and-white
M = imread(strcat(string(i)+'.jpg'));
M = im2gray(M);M = M*255;
//subplot(121)
//imshow(M,[]);
//subplot(122)
//histplot([0:255],M);
threshold = 200;
K = im2bw(M,threshold/255);
//2 Close-openL = ones(5,5);
zero = zeros(5,5);
negL = abs(zero-L);
E = erode(K,L);
D = dilate(K,negL);
Open = dilate(E,L);
Close = erode(D,negL);
subplot(131)
imshow(K);
subplot(132)
imshow(Close);
subplot(133)
imshow(Open);
//3 Label Opened image because it looks good
lbl = bwlabel(Open);
N = max(max(lbl));
//imshow(lbl,jetcolormap(N));
//4 Count area of each similarly labeled region
Area = zeros(7,N);
for j = 1:N; [x,y] = find(lbl == i);
Area(i,j) = length(x);
end
end
histplot([1:max(max(Area))],Area);
mn = mean(mean(Area))
std = stdev(Area)
//5 Eradicate noiseupperbound = mn + std + 1;
lowerbound = mn - std - 1;
Area = Area.*(Area
histplot([1:max(area)],Area);
Credits:
Lei Uy and Beth Prieto for helpful discussions, Benj Palmares for help in histogramming.
Self-evaluation: 9/10
I fell happy when labelling the regions because the resulting image is colorful
1 comment:
Good work April. This should still be Activity 10 though.
Post a Comment