|
Thursday, July 17, 2008 |
Activity 9: Binary Operations |
Given the image below, the task is to find the size of the scanned punched paper pieces.
The important concepts needed to accomplish this task is the morphological operations of opening and closing. These operations can be derived from the basic operations we obtained earlier, that is, eroding and dilating. The simple definition of closing and opening can be found from this website:
1. http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip-Morpholo.html#Heading98
Opening can (in my simple terms) remove noise or small unwanted pixel values. Close on the other hand, as the name implies, closes the object to be identified as one.
I divided the image above into 7 parts of approximately 256x256 pieces (because it was hard to splice accurately, but of the same magnification, so its okay, hehehe). And the code I implemented was my very own!
clear a chdir('G:\poy\poy backup\physics\186\paper 9'); getf('imhist.sci');
se1=ones(3,3); //square structuring element
im = imread('Circles002p1.JPG');
pref = 'Circles002p'; area=[]; counter=1
for i=7:7 im=imread(strcat([pref,string(i),'.JPG'])) im=im2gray(im); im = im2bw(im,210/255) er1=erode(im, se1); op1=dilate(er1,se1); //open di1=dilate(op1,se1); cl1=erode(di1,se1); //close [L,n] = bwlabel(cl1); reg = (L==255); for j=1:n f = find(L==j); reg_size = size(f,'*'); if reg_size <200 | reg_size > 600 L(f) = 0; end end for k=1:n area(counter) = length(find(L==k)); counter=counter+1; end scf(i); subplot(2,2,1); imshow(im); subplot(2,2,2) imshow(op1) subplot(2,2,3); imshow(cl1); subplot(2,2,4) imshow(L+1,rand(n+1,3)); end
scf(8); histplot(length(area),area); x=find(area<600 & area>450); scf(9) histplot(length(x), area(x)); a=area(x); a=sum(a)/length(x) //area y=stdev(area(x)) //error
From the first loop of the code, I attempted to eliminate the unwanted data already, that is, the large and small blobs that can be found in the image. The results of my implementation can be seen below:
This was done for all 7 segments. As can be seen from the results, the data that my code processed for the histogram was already reduced of clumped pieces of punched paper, but to be safe I also implemented that only values between 400 and 600 are acceptable. Also, using the strcat function of Scilab I was able to automatically link the 7 segments of the original image and collect data from them. (So do I get a bonus Ma'am? :D) The results of the histogram plot and standard deviation plot are shown below.
The area I obtained was 519.48 pixel values with a standard deviation of 28.127863. Using the 7th segment which does not contain any large/clumped pieces of paper to verify these results, the obtained area was 519.4! Giving us only 0.015% error!
Acknowledgements
I absolutely enjoyed this activity! Given the good values I obtained and the fun I had I give myself 10/10 neutrinos! Thank you to Dr. Soriano for her patience even when I was badgering her with a LOT of questions and Jeric for providing the histogram and area calculation part of the code.
|
posted by poy @ 6:27 PM |
|
2 Comments: |
-
Looks pretty good, Paul. I'm willing to give you a bonus if you show me the code allowing automatic stringing of multiple files.
-
Ma'am its part of my code: "for i=7:7 im=imread(strcat([pref,string(i),'.JPG']))" :)
|
|
<< Home |
|
|
|
|
|
|
Looks pretty good, Paul. I'm willing to give you a bonus if you show me the code allowing automatic stringing of multiple files.