You are on page 1of 5

lab2_image_enhancement

February 28, 2024

0.1 Topics
1. Adding one image with another to increase brightness
2. Subtracting an image from another to decrease brightness
3. Multiplying an image with a mask to increase or decrease the contrast of an image

[1]: import numpy as np


import matplotlib.pyplot as plt
import cv2

[2]: ms01 = cv2.imread('./manas_sarovar01.jpg',cv2.IMREAD_COLOR)

[3]: ms01 = cv2.cvtColor(ms01,cv2.COLOR_BGR2RGB)

[4]: plt.imshow(ms01)

[4]: <matplotlib.image.AxesImage at 0x202deee3400>

1
[5]: ms01.shape

[5]: (183, 275, 3)

[6]: m1 = np.ones(ms01.shape,dtype='uint8')*50
m1.shape

[6]: (183, 275, 3)

[7]: ms01_b = cv2.add(ms01,m1) # Brighter


plt.imshow(ms01_b)

[7]: <matplotlib.image.AxesImage at 0x202df006200>

[8]: ms01_d = cv2.subtract(ms01, m1) # Darker


plt.imshow(ms01_d)

[8]: <matplotlib.image.AxesImage at 0x202df082380>

2
[9]: m2 = np.ones(ms01.shape)*0.5
ms01_lc = np.uint8(cv2.multiply(np.float64(ms01),m2)) # Low contrast

[10]: plt.imshow(ms01_lc)

[10]: <matplotlib.image.AxesImage at 0x202df0e1cc0>

3
[11]: m3 = np.ones(ms01.shape)*1.08
ms01_hc = np.uint8(np.clip(cv2.multiply(np.float64(ms01),m3), 0, 255)) # High␣
↪contrast

[12]: plt.imshow(ms01_hc)

[12]: <matplotlib.image.AxesImage at 0x202df1497e0>

4
[ ]:

You might also like