Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Introduction

During image capture, it sometimes happens that the luminance is low due to
environmental conditions. This low luminance can result a lack of contrast in the image.
Our objective is to address this issue and improve the visual quality of the image.

On the first part of this practical work we started by correcting the luminance of the image using
histogram manipulation.

1.1) Using OpenCV and Numpy libraries, we loaded the "dark_lena.png", We then visualized the
image.

The image appeared with low luminance

1.2) After loading the image, we computed its histogram and analyzed its distribution of pixel intensity
using the Matplotlib.pyplot library.

The histogram revealed a range of pixel intensities between min:25 and max:175.
for histogram calcul we used loops: For each pixel, we get its intensity value and increment the
corresponding bin in the histogram variable array .And then we visualized the histogram using
Matplotlib.pyplot
1.4) to Correct the luminance
1- we started by calculating min and max intensity values using numpy
2- then we calculated the new pixel values using the formula:

newimage=(max−min)(oldimage−min)×255

3-we Computed the histogram of the corrected image using the same method as in question 1.2 .

1.5) The stretching technique effectively increased the luminance of the image.
On the second part we aimed to correct the contrast using histogram manipulation
So to correct an image that lacks contrast: its gray levels, are concentrated on only a few values.
2.1) like the luminance correction we started by Loading the "weak_contrasted.png" grayscale image
using OpenCV and Numpy libraries.
Then we visualized the image using cv2.imshow()

the image displayed low contrast with gray levels concentrated on a few values

2.2) Computing the histogram of the image by iterating each pixel and counting the frequency of each
intensity value.
Calculating the cumulative histogram using np.cumsum() function

the histogram indicated distribution of pixel intensities, with the low contrast observed in the image.
2.3) We divided each value of the cumulative histogram by the total number of pixels and multiply the
result by 255 .
2.4) we applied histogram equalization to the original image using the normalized histogram with
cv2.LUT() function . And then Visualized the oequalized images using cv2.imshow() .

The equalized image showed enhanced contrast compared to the original image.

2.5) for histogram of the equalized image we used cv2.calculhist() and Matplotlib.pyplot.

compared to the original image ,the pixel intensities enhanced the contrast, resulting a more balanced
histogram.
2.6) When we compare histogram stretching and histogram equalization we observed
some improvements in contrast and overall visual quality .

Histogram construction/manipulation for colored contrast correction

Using the same methods and adding some functions we successfully optimized the image colors

Before After
Conclusion
In conclusion, using histogram techniques : stretching and equalization methods , we successfully improved
thevisual quality and contrast of the images. luminance and contrast for grayscale and colored images.

You might also like