Wednesday, July 11, 2012

Histogram Manipulation

Since my first image of the Milky Way (which was last January this year), I've already been using the Curve Tool in Photoshop to enhance my image - make the Milky Way more visible. I was new to Photoshop then so I explored the software. It really amazed me how images looked much better after tweaking the Curve tool. But somehow, I thought I am only cheating because I am tweaking the curves.

Until the lesson we had on Histogram Manipulation...

The lesson actually fascinated me since it now explains how the Curve tool works and how is it possible to make details come out even when they are not there in the first place. Of course, since it is a really interesting topic for me, all ears on Ma'am Jing! =D

The image that I used is shown below. This was taken last January 2012 at Caliraya, Laguna. On site, another amateur astronomer (Kuya Irving) was teaching me how to do astrophotography. This was one of my first shots using the techniques I just learned then.

Image to be enhanced

The image was first converted to grayscale. The histogram and the normalized histogram or cumulative distribution function was then taken.

Grayscale version of the Original image
Histogram and the CDF of the original image

Here is the code used for the images above.



In order to manipulate the histogram, we need to use backprojection.

How are we going to do that?



Simple. Just like the Curve tool, we also need to tweak the CDF by introducing a desired CDF. Now, we start with the basic and very common one - a linear CDF. A linear CDF indicates that the white and black pixels are uniformly distributed.

First, we get the corresponding CDF, y1,  of x1. Then, find the value of the same CDF of the original image in your desired CDF, y2. Once found, check the corresponding x2 of y2. Replace x1 with x2. Do this for all values of the grayscale from 0 to 255.

Here is the code I used.



The algorith, for the code is shown as follows:



RESULTS


Linear:

Image after implementing a linear CDF

Histogram of the enhanced image using a linear CDF

A comparison of the desired CDF (left) and the resulting CDF (right)

 Quadratic:




Image after implementing a quadratic CDF




Histogram of the image above

A comparison of the desired CDF (left) and the resulting CDF (right)


The difference in the resulting images compared to the original is observable. It can be observed that histogram of the resulting images has shifted and that their CDF is either linear or quadratic in form but neither is smooth.

While this topic proved to be interesting and really useful, it may not seem really practical to other people since the process is quite "long" and "tedious". You need to have the correct function in order to get a really good enhanced image. Softwares such as Adobe Photoshop and Gimp provides the appropriate tool for image manipulation. 

Using Adobe Photoshop

Using Gimp

Here are sample enhanced images. These are my treasured Milky way shots and the only thing I tweaked to make the details come out is the Curves tool :)

Original Image 1

Enhanced Image 1

Original Image 2

Enhanced Image 2

There ya go! Image processing is really fun and interesting. Oh, how I wish we have more Image processing subjects.

Anyway, I give myself a 13. I really worked hard for this (because it took me a while before getting the right code and lots of editing). I would like to thank Mabelle for helping me understand the concept better and to Ate Jen's blog for making me see what went wrong in my code. :) Of course, thank you, Ma'am Jing, for simplifying things for us and for making the lessons as enjoyable as possible. :)

References:
1. Soriano, M. Image Enhancement by Histogram Manipulation 2010.
2. Manuel, J. Scilab Playground.

No comments:

Post a Comment