Activity 10: Looping Through Images

September 2, 2012

The first part of the activity is to determine the average size (in pixels) of a desired shape scattered all over an image.

Starting of with our original image of scattered punched paper left-overs, I have divided the image into 9 equal sections through the use of the crop() function (which was discussed previously) in Scilab. As seen in my code below, there is an obvious pattern as to how the cropping thing works in Scilab:

However, whenever I try to append the individual matrices of the ‘cropped’ portions to a new list so that I can just call them one by one inside a for loop… they always end adding up which ultimately leads back to the original uncropped image! I had no choice but to individually save these images and call them whenever it’s their turn to be processed. Also… I know I can easily make a loop to call the divided images and process them.. However I chose not to as the images have different features on them. The end-product of a certain set of morphological functions may seem to fit  image A but then it might not have that much effect on image B.

Anyway, going back to the activity proper…. All images were binarized through the use of the im2bw() function. What’s nice about this function was the presence of the threshold parameter. Varying the threshold enabled me to choose the value which gave the best output only having the circular patterns we want. Besides having to determine the threshold value through inspection, the use of the histogram could be done as displayed below:

The next step in finding the average size of these circles is to try and separate them. This is where the powerful and oh-so-useful morphological functions play. Using different combinations of the ErodeImage() and OpenImage() functions with different Structural Elements, I ended up cleaning the image a little bit. HOWEVER, there were some very persistent circular patterns which I could not separate no matter what type of morphological functions as well as structural elements I’ve used. Opening and Eroding the image too much causes significant loss to some of the already separated circles. Hence, I just decided to leave them as is and dealt with them later on.

Having cleaned up our image, we can now separate the circles not only physically but also through labels. How do we do that? I have already introduced the bwlabel() function available in SIP in my previous activity… However, I have found that SearchBlobs() function more useful as the IPD toolbox has a lot of functions that makes the whole thing easier :).  The only tricky thing in dealing with the blob functions in IPD is that the output of these functions are changed into different types (uint 32). Simply calling the outputs would lead to an error. Thanks to Dr. Eng. (J) Harald Galda, 2011’s tutorial PDF available in here, I have finally found a way to display their outputs which is through the use of the ShowImage() function and the conversion of the output to uint8(). A test to see how much ‘blobs’ were detected by the function is by typing in max(BlobImage), where BlobImage is the output of the SearchBlobs() function.

As I’ve said earlier, there are a lot of  blob functions useful in the IPD toolbox. One is the FilterBySize() functions.  What this does is that it removes the ‘blobs’ having certain areas smaller than what you’ve indicated. This function asks for two parameters: (a) the output matrix of your SearchBlobs, (b) the threshold area. This enabled me to remove more unwated blob leaving me with only the blobs pertaining to the circles.  This is observed by yet again using the max(Filtered) function:

max(BlobImage) gives out 15 while max(Filtered) gives out only 10!!

As an additional note, the jetcolormap() was used to show how each blob was recognized. The different shades of colors simply shows that the respective blobs is considered as a single entity.

Now that we have successfully labeled the respective circles, it is now time to find their areas! Using the   code I have used in the note-recognition portion from the “sing me a song” activity… I am able to easily get the respective number of pixels  contained in each circle. But then you may have noticed that certain blobs are actually composed of two or more circles that I have failed to separate earlier… The only solution I could think of is through the use of the if functions as seen in the code below:

Take note that the code above is not the final code I have used… I varied the conditions in the if function depending on the image I’m dealing with..

As a result, I end up with the following table:

Taking the average of these values gives me the average area of each circles to be 424 pixels with a standard deviation of 81 pixels.

The second part of this activity tests how we are able to manipulate images from the things we’ve learned so far. Given a new image of scattered punched-paper left-overs only this time there are overly large cut outs, we are to detect these cancer cells!

Again, we start off by binarizing the image through the im2bw() function with the corresponding threshold value. The next thing is to make use of different morphological functions again so that we can separate the circles that appear to be overlayed. I did everything that I can to end up with the image below:

Even though we can now clearly see the cancer cells we so want to detect…it is noticeable that there are still large clusters in our already processed image!  Using the SearchBlobs() function and again the FilterBySize() function with the corresponding threshold value chosen by inspection, I am now left with this:

I am still left with two unwanted blobs! Who would want to pretend that they’re cancer cells right?! Varying the threshold value I was using for the FilterBySize() function already removes a cancer cell that apparently is smaller than an unwanted blob. I could no longer find a way to remove these unwanted blobs further…

However, playing around with Scilab me to the discovery that I can actually convert this to a matrix with each of the blobs having their own respective grayscale values. Luckily, the cancer cells have values lower than the two unwanted blobs! This then enabled me to remove them by simply using the find function as well as specific conditions (only those of intensities lower than 80% of the maximum of the matrix and greater than 0 will be included).

I know it’s a bit messy but it was able to give me this image:

FINALLY!!

Note: For this activity, I would like to give myself a rating of 10 as I have managed to do all the requirements. I bet this activity would’ve been fun to do but due to the load I currently have (with the upcoming SPP deadline and papers and midterms and problem sets all due at the same time)… I had to rush into finishing this activity sooner. I know I could’ve explored on the things the blob functions in the IPD toolbox can offer but having my help files in Japanese… I had to do my own tricks for certain portions of this activity.

Leave a comment