IP Experiment 6 An
IP Experiment 6 An
TOOL:- Python
THEORY:-
Based on the histogram distribution, an image can be categorized into three types:
1. Dark Image: If most of the pixel intensities are concentrated towards the
lower gray levels (close to 0), the image appears dark.
2. Bright Image: If the pixel intensities are mostly towards the higher gray levels
(close to L-1), the image appears bright.
3. Low Contrast Image: If the pixel intensities are mostly concentrated in the
middle gray level range, the image has low contrast, making it appear dull and
lacking in details.
where:
Each pixel intensity level rk in the original image is mapped to a new intensity level
Sk in the output image, thereby spreading the intensity values over a wider range.
𝑛
𝑘
𝑟
𝑘
𝑛
𝑘
𝑟
𝑘
ALGORITHM:-
CODE:-
import numpy as np
import cv2
if img is None:
img = np.array(img)
flat = img.flatten()
plt.figure(figsize=(10, 6))
plt.subplot(2, 2, 1)
plt.title('ORIGINAL HISTOGRAM')
histogram[pixel] += 1
return histogram
def cumsum(a):
b = np.zeros_like(a)
b[0] = a[0]
return b
cs = cumsum(hist)
N = cs.max() - cs.min()
cs = (nj / N).astype(np.uint8)
img_new = cs[flat]
plt.subplot(2, 2, 2)
plt.title('EQUALIZED HISTOGRAM')
# Display images
plt.subplot(2, 2, 3)
plt.title('ORIGINAL IMAGE')
plt.imshow(img, cmap='gray')
plt.axis('off')
plt.subplot(2, 2, 4)
plt.title('EQUALIZED IMAGE')
plt.imshow(img_new, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()
RESULT:-
CONCLUSION:-