Our lecture in our other class, AP 187 can be applied here regarding the process of how we perceive images. The image you see in the monitor such as in this picture is a result of multiple factors.
A night to regret este remember :)) :P
If only we could see everyone in this picture...
And that's why candle light is not the preferred method of lighting in this day and age
The image may appear dark to our eyes but as we should already know by now, our eyes are liars. That's why we shouldn't judge a book by its cover nor an image by its color. Haha. We judge an image by its histogram!
Based on this histogram, there is still hope for this picture.
Interestingly, it only takes a few lines of code in Scilab to output the histogram. It is easy to see how Scilab is optimized for these kinds of image processing. Of course, I'd still prefer Photoshop or Gimp for image manipulation. On the other hand, there is still a different sense of accomplishment of actually typing your own code to edit your own pictures. I'm proud to say that I was able to write the code on my own with minimal help from others. I can really feel that I'm learning a lot about Scilab. I almost finished the entire code in one sitting during the class time. It's not absolutely fast. I can imagine Chester laughing at me but this is a big improvement for me. I still encountered a few problems though. One of them is that I was unable to normalize the histogram. I plotted it too so that I could normalize it.
I'm still learning okay?
The CDF was easily computed using cumsum.
almost 80% of the pixels have a value of around 50
Actually, the heart of this code is in the process of redistributing the numerical values of each pixel in the image to follow a ramp cdf. After some thought, I found that it could be coded into a single line:
ni(find(ni<256)) = 255*cdf(ni(1:length(ni))+1);
Credits to Alix for suggesting using the find function as an easier way of replacing the values instead of making a new array. Again, there is a warm sense of accomplishment of finding a solution and in just a single line. I would also like to boast about a solution to the one imshow per run problem. Again, it may not be a big deal to you, but I'm happy I found it. The workaround is simple. Just put the two arrays together such as in this line:
both = [gi ni];
where gi is the original grayscale image and ni is the new image. Then I just imshow both. Doing that, we have the images side by side for comparison. Of course the image below is the result of imwrite.
Now you don't see me, now you do. Seriously. Comment if you get it.
Now that I think about it, there is a flaw in this procedure namely the color was lost. Now I'm wondering if there was a way to get the color back.. Of course, you can do image enhancements like this in Photoshop or Gimp. I then realized that probably, they use similar algorithms to carry out such processes.
Getting back to the resulting comparison. Can I just say that I'm not that dark. Seriously. Did you notice me in the original image? I'm in the upper right corner of both pictures but I can only be seen on the edited image. I guess I'm just too far from the light source. Moving on to other observations, of course, the image is much brighter. Mam would argue that the contrast improved. Actually, I think it's both. This can be seen in the new histogram and the CDF.
The new histogram shows better contrast and brightness
The histogram shows how the pixel values are redistributed to improve the image. Contrast is basically the difference between light and dark. The bright is represented by the higher x values while black is represented by 0. Previously, as I said, majority of the values are below 50, which is dark. The new image now shows a bigger range. As seen in the CDF as well, there is now a linear distribution of values from 0 to 255.
The new CDF follows a linear trend as expected
Brightness, on the other hand, is the number of pixels in the higher values. Again, as we see in the histogram, the values are shifted to higher values and there are now more pixels in the higher regions.
Another observation in the image is the noise made in the very dark areas such as in Tor's suit. The answer, I think, can be seen in the new histogram as well. As mentioned before, the code shifted the the values to higher values. What is notable in the histogram is how the very dark pixels are much more spread apart. This means that some pixel values that were originally very similar were suddenly shifted to have very different values. The result is that adjacent pixels alternate between light and dark resulting in a grainy image. The start of the new CDF that looks like steps is also related to this. Since large amounts of a certain value are shifted, there is no fine adjustment. I get it but am having a hard time explaining it. Anyway, I guess one way to improve this is to have a smaller bin size or more values, not just 0-255. Of course, I realize that if a similar process is used in commercially available image enhancement software, they find ways of improving the algorithm.
coded in Scilab for more than 3 hours. got the same thing in Gimp in less than 3 minutes.
However, the sense of accomplishment can be approximated as inversely proportional to time.
A similar result can be obtained by manipulating the input output or response curve in Gimp. Basically, the input is the image and the output is linear. changing the response curve changes the brightness of the image.
Again, I enjoyed coding. As it turns out, the code is not that long and just challenging enough for me to figure out with minimal help.
//Activity 6, Histogram Manipulation code
//by Joshua Beringuela completed on July 2, 2013
//read image, convert to gray scale,
//output histogram and CDF, and apply ramp CDF
oi = imread('C:\Users\Shua\Desktop\di2s.jpg');
gi = rgb2gray(oi);
ni = gi
scf(1);
h = imhist(gi,256,'')/length(gi);
scf(2);
plot(h);
cdf = cumsum(h);
scf(3);
plot(cdf);
ni(find(ni<256)) = 255*cdf(ni(1:length(ni))+1);
both = [gi ni];
imshow(both);
scf(4);
nh = imhist(ni,256,'')/length(ni);
cdf2 = cumsum(nh);
scf(5);
plot(cdf2);
//imwrite(both,'a6.png')
No comments:
Post a Comment