Name - Bhavya Jain 19CS19 Batch C1 Digital Image Processing Lab
Name - Bhavya Jain 19CS19 Batch C1 Digital Image Processing Lab
19CS19
Batch C1
Digital Image Processing Lab
1. Perform Histogram Equalization for the input
“image1”.
Description: Histogram Equalization is an image processing technique that
adjusts the contrast of an image by using its histogram. To enhance the
image’s contrast, it spreads out the most frequent pixel intensity values or
stretches out the intensity range of the image. By accomplishing this,
histogram equalization allows the image’s areas with lower contrast to gain a
higher contrast.
Solution Code:
import cv2
import numpy as np
img = cv2.imread('/content/image1.jpg',0)
equ = cv2.equalizeHist(img)
res = np.hstack((img,equ)) #stacking images side-by-side
cv2.imwrite('res.png',res)
INPUT IMAGE
OUTPUT IMAGE
BEFORE AFTER
2. Perform Histogram specification/matching for the
“image2”. Take the histogram of “imagex” as the
specified histogram.
Description: Histogram matching allows us to update the pixel intensities
in an input image to match the pixel intensities’ distribution in a separate
reference image .
Histogram matching can best be thought of as a “transformation.” Our goal
is to take an input image (the “source”) and update its pixel intensities such
that the distribution of the input image histogram matches the distribution of
a reference image.
Solution Code:
import matplotlib.pyplot as plt
from skimage import exposure
from skimage.exposure import match_histograms
import cv2
` img1 = cv2.imread("/content/image2.jpg")
print('No of Channel is: ' + str(img1.ndim))
img2 = cv2.imread("/content/imagex.jpg")
image = img1
reference = img2
ax1.imshow(image)
ax1.set_title('Source')
ax2.imshow(reference)
ax2.set_title('Reference')
ax3.imshow(matched)
ax3.set_title('Matched')
plt.tight_layout()
plt.show()
source_range='dtype')
axes[c, i].plot(bins, img_hist / img_hist.max())
img_cdf, bins = exposure.cumulative_distribution(img[...,c])
axes[c, i].plot(bins, img_cdf)
axes[c, 0].set_ylabel(c_color)
axes[0, 0].set_title('Source')
axes[0, 1].set_title('Reference')
axes[0, 2].set_title('Matched')
plt.tight_layout()
plt.show()
INPUT IMAGES
image2 imagex
OUTPUT IMAGE
3. Apply 3x3 and 5x5 median filter on “image3” and
“image4” (apply both masks on both the images).
Solution Code:
im1 = Image.open(r"image3.jpg")
INPUT IMAGES
image 3 image4
OUTPUT IMAGES
Image3
3*3 median filtering 5*5 median filtering
Image 4
3*3 median filtering 5*5 median filtering
INPUT IMAGES
image 3 image4
OUTPUT IMAGES
3*3 mean filtering(image 3)
Solution Code:
import numpy as np
from numpy.lib.stride_tricks import as_strided
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import matplotlib.gridspec as gridspec
import seaborn as sns
import math
import cv2
img1 = cv2.imread("/content/image3.jpg")
add_av_fil = np.array([[1, 2,1],
[2,4,2],
[1,2,1]], np.float32)/16
INPUT IMAGES
image 3 image4
OUTPUT IMAGES