We all have that one photo we took that somehow is dark. You get frustrated and asks if somehow you can see what you were taking a picture of.

Well aren’t you a lucky person, we’re doing just that in this blog! Take this image right here for example. Isn’t it pretty? Let’s see if we can find my friend in the dark.image.jpg

First, let’s try to do this in a grayscale enviroment. We’ll use rgb2gray() to make the image into grayscale like soorg.JPG

Now what we are going to do is to manipulate the histogram of the image to recover information that is being blacked out in an image.

raw = rgb2gray(imread(‘image.jpg’));
raw2 = double(raw)

[counts, bins] = imhist(raw,256);
cdf = cumsum(counts/sum(counts));

As we all know imhist provides the probability density function or p(r)   (PDF) of the image. If we take the cumsum() of the counts, then we’ll obtain the cumulative distribution function or T(r) = \int^r_0 p(g) dg (CDF).

What we want to do is to map the r‘s to a different set of gray level z‘s such that the new image will have a CDF given by

G(z) \int^z_0 p_2(t) dt

where p_2(t)  is the PDF of the transformed image and t is a dummy variable. Essentially, this is what we are supposed to do.

figs.JPG

Now back to finding my friend, let’s make a linear and a sigmoidal CDF.

Using these ideal CDFs, let’s try to backproject it to obtain an image, shall we?

This slideshow requires JavaScript.

Oh there she is!

Here are the CDF post-processing,

 

We can see from here that the linear CDF produces a decent result however, it is noisy. The Sigmoid CDF also has noise but it is more tolerable. I think I’ll use the sigmoid from now on.

In this post, I think I can give myself 9/10 rating since I think I know the topic and reproduced the target image. Although, I guess I haven’t mastered SciLab enough to be able to understand fully the way to get the colored image up and running. I mean, I tried translating the 2D image into 3D, but I ended up with this mess

color.jpg

It seems that I lost my friend again, but now in color and not in the darkness. Peace y’all!

I’d like to thank my friends for helping me out. I tried to do the implementation on my own, and I didn’t make it. Anyway, thanks Louie, Pat, Jona and babe Trixia.

Advertisements