top of page

Activity 10

Enhancement by

Histogram Manipulation

Oh how I love writing the blog introductions. These times you feel that the semester is about to end because all reports and requirements are starting to pile up. But tenacity is one key to success so gogogogo!

I very much enjoyed the past Activity on playing music on scilab so please do check it out. :)

This next activity is quite as fun - I hope. It's all about histogram manipulation.

I have ingrained it to my brain what Ma'am Jing said that the most important lesson that we should take away from the course is that we should not trust our eyes.

This activity demonstrates this by manipulating an image that seems to contain low information.

Just a head up. This blog post is full of vanity. I used my personal photo to be subjevted to histogram manipulation.

When we look at the grayscale histogram of an image, we are actually looking at the graylevel probability distribution function (PDF) of that image. Modifying this PDF allows us to modify the quality of the image and enhance hidden features. This process is what we call histogram manipulation.

Honestly, this is not a very new concept for me. I do this very often in photoshop when I improve seemingly dark images by changing the shape of the histogram curve. The only catch this time is that I am gonna do it in SCILAB.

From the PDF of an image, we seek to obtain a cumulative distribution function (CDF) that we will use to backproject the grayscale values of the PDF.

Here are the basic steps that I did. I scavenged through my personally vain photos and got a relatively low light image of my face after an open water dive. The image is shown below together with its grayscale.

I swear though that the image is more crisp and dark when viewed with a Macbook Pro. :( I'm looking at the site with a different screen and  the quality of the image is not good even the its size is 8MB. Shown below is the PDF and the CDF of the image. The PDF is just a plot of the number of pixels per grayscale value and the CDF is the cumulative sum of those pixel values in the PDF per grayscale value.

grayscale

We see from the shape of the PDF that indeed most of the pixels are dark and the CDF indicates this "polarity" in pixels as seen by the flat line at the middle. One method for us to enhance the image is remapping the CDF with both linear and common non-linear functions.

The programming part was done in SCILAB and I used cumsum() to calculate the CDF. The first function that I used is a linear function [y = x]. Shown below is the output image together with its PDF and CDF.

linear

As we can see from the result, the PDF is generally flat, meaning the pixel values are well distributed. And the CDF was successfully remapped as a linear function. The next function I tried is the familiar quadratic function [y = x^2]. Show below are the results:

quadratic

As expected, the PDF for a quadratic function has high density at higher grayscale values. The CDF says it all about the success rate of this manipulation. One good thing to comment though, I am very particular on images I use online. Since I am always using "good" quality images, my code runs so long. It took me around thirty minutes to generate per image in this blog. Or maybe its just my computer. 

Moving on to the next non-linear function, I chose the dreaded logarithmic function [y = logx]. Dreaded because when you see it in calculus exams, the answer (or the solution rather) would probably be not at all pretty.

logarithmic

So far, the linear function provided the best enhancement so far. The quadratic function is too bright while the logarithmic is extremely dark. This "darkness" in the exponential sense is because the pixel values are concentrated at lower values in the PDF. Again, the success rate is indicative from the CDF. :)

The next non-linear function is rather "uncommon". To non-physics people that is. To generate the sigmoid function in SCILAB, I used erf() - the majestic error function. Shown below are the results:

sigmoid

The PDF looks like a Gaussian curve. It has be. And the CDF is the familiar sigmoid curve. The quality of the image generally gray and is not that good as the linear function.

 

For fun, I tried rounding-off the sigmoid function with SCILAB's round() function, and voila!:

rounded sigmoid

Just a little push and I'll make my own photoshop package in SCILAB. The last part of this activity involves my face again. But this time I'll try to do histogram manipulation in colors! Using my vast knowledge in image segmentation, I transformed my face in normalized chromaticity coordinates I, r and g. Please visit Activity 7 if you need a recap. I performed histogram manipulation on the I channel and retrieved the new RGB's by multiplying r, g, and b respectively to the enhanced I channel. For the enhancement, I used a linear function since it proved to be the best with the grayscale images. Now you are able to see my blemishes.

First of all, I would like to thank my self for being a very willing subject for this image histogram manipulation. I enjoyed this activity equally to the previous activity on making SCILAB sing.

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, “A10 - Enhancement by Histogram Manipulation,” Applied Physics 186 Activity Hand-outs, 2016.

bottom of page