top of page

Activity 7

Image Segmentation

Wooooohhhhoooooooo! I survived the first half of the semester! Or so I think. It's already my sixth year and UP and yet every single day seems to be different. Indeed my day to day college life is not like a routine, like others have lived theirs. I was late today in class for I joined a solidarity movement for the indigenous group called Lumad. They are camping for a month in UP grounds for Chancellor Tan welcomed them as guests. Just the day before, as the IP group was peacefully conducting their protest in front of the US Embassy, police troops violently dispersed them by mauling them over with a patrol car. Some of the victims are still unconscious.

The IP groups came from all over the country to stage their protest for their displacement from their ancestral lands. Their chieftains are being killed and they are harassed by paramilitary troops for their land is reach with gold and minerals.

We really need national industrialization in the country. Multinational corporations are looting with our resources with very unfair conditions.

Anyway, back to the activity. Activity 7 is all about image segmentation. In image segmentation, a particular region of interest (ROI) is selected for further processing. In this activity i will employ two segmentation processes; grayscale and color segmentation. For the first process, consider the image below:

The one who owns this check is probably a math geek. Why would someone place a summation and an infinity symbol in a pay check? Anyway, exp(i*pi) = -1 and the geometric term is equal to 2. So the paycheck is not that big after all (=1.002 dollars or 48.36 pesos). The goal is to isolate the handwritten text.

To do it, I plotted the grayscale histogram of the image shown below:

The peak in the plot corresponds to the pixels of the background since it occupy more space compared to the text. Different threshold values can be used isolate the text. For example:

threshold values

50

75

100

125

150

175

200

From the images, we see that for lower threshold values, the texts are more apparent but for very low values only thick parts of the texts are left. On the other hand, for higher threshold values, the background becomes more apparent. By visual inspection,one can say that text isolation is best at the threshold value of 125.

The next part of the activity is on the image segmentation of a colored image.

 

Current methods in image processing uses color for feature recognition techniques, remote sensing, and cell imaging. In particular, 3D unicolor objects would be seen with different colors or shades of the original pure color. Therefore, it is best that color representation of 3D objects be described by brightness and chromacity and not only by RGB (it will just look flat or depthless). 

One particular color representation is the normalized chromaticity coordinates or NCC. Mathematically,

where R, G, and B are the red, green and blue components of the object respectively while r, g, and b are the normalized chromaticity coordinates. To decrease the dimensionality by one, it is assumed that r + g + b =1. Thus the normalized blue component can be represented as b = 1 - r - g. Plotting r versus g:

Parametric vs Non-Parametric Probability Distribution Estimation

The two general methods used to segment an image are parametric and nonparametric segmentation technique. The main difference between the two is that parametric technique uses a Gaussian probability approximation to identify a segment from the image while nonparametric technique uses histogram backprojection.

                                Parametric

The blue component is taken in terms of the red and green. Invoking properties of trichromaticity, any color can be composed by optimizing red and green values in the NCC space.

In parametric reconstruction, a segment is determined by considering the probability of a pixel belonging to a particular color distribution. In particular, the color histogram of a region of interest (ROI) must be obtained and "correlated" to the whole image. The probability distribution function (PDF) of the color can be represented by normalizing the color histogram of the ROI by the number of pixels. Since we operating on the NCC space, we consider the color probability to be the joint probabilities of r and g that is p(r) * p(g). These two probabilities in r and g can be assumed to follow a Gaussian distribution which is independent of each other for simplicity. The probabilities are given by:

where the variable mu represents the mean and sigma the standard deviation. Since Christmas season is near, I chose the image below as the subject:

I chose a "green" region of interest:

Implementing the joint probability algorithm in SCILAB I obtained:

Non-Parametric Estimation

In this method, the actual histogram of the ROI is used to correlate to the individual pixels of the image. It uses a technique called histogram backprojection that assigns a value to a pixel location equal to its corresponding value in the NCC space. Unlike the parametric approach that needs probability computaion, the nonparametric estimation is faster since it just compares histogram values. The histogram is obtained by converting the r and g values of an image into integers and putting it into a matrix. I used the same subject image as above and the same ROI. I obtained the following result:

                

As can be seen, the segmentation was success indicated by the isolation of the green patches from the original image. The next part includes the nonparametric segmentation technique.

Both method were successful enough to segment the green region from sugbject image. For the nonparametric estimation, I obtained the 2D histogram of the ROI, to compare its location with the NCC coordiantes as shown: 

parametric

Exploration

To better understand the usability of the parametric and nonparametic approach to image segmentation, I considered a more complex image of a fire vortex as shown:
                              

I obtained two different ROI for the image, one with a uniform color distribution the other with more shades of orange.  I implemented the algorithm above and got the following results:

nonparametric

As we can see from the images, for solid colored ROI, the parametric approach segemented finer details while for the "shady" ROI the nonparametric approach fared better.

Why is this so? Let us look into the details of the implementation of both approaches. The parametric approach will only work if the PDF of the ROI follows a Gaussian distribution (e.g. the color of the ROI approximates a single color). Therefore it will fail to three scenarios: (1) if the ROI contains more than one color or shade, (2) if the Gaussian distribution cannot sum the actual PDF and (3) the background has the same colors with the ROI.

 

For the nonparametric estimation, it works even for scattered histograms and multicolored ROI because it just compares histogram values to the actual image and bins it. As with the parametric method, it will not work for images with the background having the same color as the ROI. Although it is subjected to the limitation of the bins, it proved to be robust in terms of speed and ease in implementation.

To be honest, I had a lot of struggles while doing the activity. Aside from me being sick that is. I am using a Mac and recently upgraded to Sierra OS. Wrong move. It didn't allow me to use SCILAB because of technical glitches in the source code. :( So desperate as I was to finish the activity, I was forced to buy a desktop with a Windows OS to run SCILAB (SIVP + IPD). At least now, all is working smoothly and I am enjoying coding in SCILAB (not in MATLAB anymore) with a PC dedicated for SCILAB only. =D

I would give myself a rating of 12/10 for producing all the required images. I would like to thank wix.com for their very nice website platform.

Reference:

[1] M. Soriano, “A7 - Image Segmentation,” Applied Physics 186 Activity Hand-outs, 2014.

[2] openclipart.org. Christmas Tree Collage.

[3] videoblocks. Fire Vortex. https://www.videoblocks.com/video/fire-vortex-animation-d68myfr/

bottom of page