Thursday, July 7, 2011

V

Using Photoshop familiarized me on how histogram tweaking can affect the light and dark levels of my image. However, this time, we get to see the gritty parts of how it is actually done: by treating the image as a matrix and performing statistical operations to alter the distribution of its pixel values.

Numerically converting the image's Cumulative Distribution Function (CDF) to another one is the main idea behind this:
 (1)

Eq. 1 shows the CDF from r to z values, where the p's are the corresponding PDFs. Hence, the corresponding pixel value z is given by Eq. 2:
(2)


Figure 1. Visualization of the transformation process



Figure 2. Top to bottom: Original image, its histplot() and CDF

Figure 3. Code for generating the CDF

Fig. 2 shows the original image I've used for this activity. It is very dark, however, its histogram shows that information is stored and we're just visually handicapped to see this. From the bottom image, its CDF immediately rises, giving us the idea that most of its values are situated nearer to the dark (0) pixel values.




Figure 4. Top to bottom: Transformed image, its histplot() and CDF

For a uniform distribution, we have a CDF that is a straight line. This means that the values are equally distributed so that the cumulative sum is linear. Employing the technique illustrated in Fig. 1, with a straight line as a new CDF, I get Fig. 4. The image became more clear than the original. Details can now be seen that were undiscernable before. We see from its histplot() that the distribution is almost equal in the value range, clearly a result of the new CDF applied to it. I have applied the code shown in Fig. 3 to the transformed image to check if it has really acquired the linear CDF. As we can see, the graph obtained is linear. I am finally successful.

I now try for a non-linear CDF. I use a cubic function (y=x^3) and get these:



Figure 5. Top to bottom: Transformed image, its histplot() and CDF

Again, the light areas of the image became more noticeable due to the new CDF. Since it is cubic, the histplot() roughly shows a quickly increasing histogram. Thus, the image became more concentrated on the range close to 1, translating to an overall increase in white-ish pixel values. Checking the generated image's CDF, we see that it is indeed cubic.

Figure 6. Code for the CDF transformations used.

Fig. 6 shows the code I've used for doing the whole transform. Note that I've used gray_imread() so that I deal with a single channel only, obviously. Overall, it has appropriately satisfied the method, and the small bumps from the CDFs of the images that I've transformed come from the fact that the images are not exported right out through imwrite() because I can't find a similar argument, [], as in imshow() to correctly display the image. I have resized the scf() window and  used the File -> Copy to clipboard option of the display window.

To gain an insight to more advanced processes with histogram manipulation, I play around my image in GIMP. Using the Curves option, I got these:


Figure 7. Curves in GIMP 2


Trying to find a correlation between this movable line in GIMP with the CDF that I've transformed above, I get the feel that the response is somewhat flipped along that diagonal line. This may be due to GIMP treating the original image's CDF as linear, hence the diagonal line. The cubic CDF when flipped, would then be similar to the top image of Fig. 7.

Similarly, Photoshop Elements has this, too (Fig. 8). It even has presets.

Figure 8. Photoshop Elements 6.0 curves interface

For me, this was a messy activity in terms of coding the transform. Psh.

  Self-Assessment: 9/10 
Acknowledgements: T.J. Abregana, T. Tuballa and K. Cheng for their help in coding.

No comments:

Post a Comment