You are on page 1of 28

School of Computing

Science and Engineering

Program: B Tech
Course Code:BCSE3045
Course Name:DIP
School of Computing Science and Engineering
Course
ourse Code
Code :: Course
Course Name:
Name:

Course Outcomes :

Program Name: Program Code:


School of Computing Science and Engineering
Course
ourse Code
Code :: Course
Course Name:
Name:

Course Prerequisites
Computer Graphics

Program Name: Program Code:


School of Computing Science and Engineering
Course
ourse Code
Code :BCSE3045
:BCSE3045 Course
Course Name:
Name: DIP
DIP

Syllabus
• UNIT-I INTRODUCTION 9 HOURS
• Introduction: What is digital image processing, origins of digital image processing, examples of fields that use dip, fundamental steps in digital image
processing, components of an image processing system; Digital image fundamentals: Elements of visual perception, a simple image formation model,
basic concepts in sampling and quantization, representing digital images, spatial and gray-level resolution, zooming and shrinking digital images, some
basic relationships between pixels, linear and nonlinear operations.
•  
• UNIT-II IMAGE ENHANCEMENT IN THE SPATIAL DOMAIN 9 HOURS
• Image enhancement in the spatial domain: Some basic grey level transformations, histogram processing, enhancement using arithmetic/logic
operations, basics of spatial filtering, smoothing spatial filters, sharpening spatial filters, combining spatial enhancement methods; Image
enhancement in the frequency domain: Introduction to the Fourier transform and the frequency domain, smoothing frequency domain filters,
sharpening frequency domain filters, holomorphic filtering.
•  
• UNIT-III IMAGE RESTORATION AND FILTERING 9 HOURS
• Image restoration: A model of the image degradation/restoration process, noise models, restoration in the presence of noise only spatial filtering,
periodic noise reduction by frequency domain filtering, Image filtering: Linear position invariant degradations, estimating the degradation function,
inverse filtering, minimum mean square error (wiener) filtering, constrained least square filtering, and geometric mean filter.
•  
• UNIT-IV IMAGE PROCESSING 9 HOURS
• Color fundamentals: Color models, pseudo color image processing, basics of full-color image processing, color transformations, smoothing and
sharpening, color segmentation, noise in color images, color image compression; Wavelets and multi resolution processing: Image pyramids, sub band
coding, the harm transform, multi resolution expansions, wavelet transforms in one dimension, fast wavelet transform, wavelet transforms in two
dimensions, wavelet packets
•  
• UNIT-V IMAGE COMPRESSION AND SEGMENTATION 9 HOURS
• Image compression: Fundamentals, image compression models, error-free (lossless) compression, lossy compression. Image segmentation: Detection
of discontinuities, edge linking and boundary detection, thresholding, region-based segmentation.

Program Name: Program Code:


School of Computing Science and Engineering
Course
ourse Code
Code :BCSE3046
:BCSE3046 Course
Course Name:
Name: DIP
DIP

Recommended Books
Text books
• Rafael C. Gonzales, Richard E. Woods, “Digital Image Processing”, Pearson Education, Third
Edition, 2010.
• Fundamentals of digital image processing by A.K.Jain.
Reference Book
• Jayaraman S., Esaki Rajan S., T.Veera Kumar, “Digital Image Processing”, Tata McGraw Hill
Pvt. Ltd., Second Reprint, 2010.
• Bhabatosh Chanda, Dwejesh Dutta Majumder, “Digital Image Processing and analysis”,
PHI Learning Pvt. Ltd., Second Edition, 2011.
• Malay K. Pakhira, “Digital Image Processing and Pattern Recognition”, PHI Learning Pvt.
Ltd., First Edition, 2011.
• Annadurai S., Shanmugalakshmi R., “Fundamentals of Digital Image Processing”, Pearson
Education, First Edition, 2007.

Additional online materials

Program Name: B. Tech. Program Code:


References
• https://
github.com/topics/histogram-matching
• https://docs.opencv.org/3.2.0/d5/daf/tutorial
_py_histogram_equalization.html
Installation of OpenCV with python
To verify opevcv

• Type
– Python
– Import cv2
• It must not give any error
Check version
• >>cv2.__version__
You can do with Visual Studio
• Install visual studio (VS)
• Click on extention
• Inside the VS install python and OpenCV
Here is a simple code for just loading the
image:
• import cv2
• import numpy as np
• from matplotlib import pyplot as plt

• gray_img = cv2.imread(‘GGSunset.png', cv2.IMREAD_GRAYSCALE)


• cv2.imshow('GoldenGate',gray_img)
• hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
• plt.hist(gray_img.ravel(),256,[0,256])
• plt.title('Histogram for gray scale picture')
• plt.show()

• while True:
• k = cv2.waitKey(0) & 0xFF
• if k == 27: break # ESC key to exit
• cv2.destroyAllWindows()
Histogram Gray Scale
• An image histogram is a type of histogram that acts as
a graphical representation of the tonal distribution in
a digital image. It plots the number of pixels for each
tonal value. By looking at the histogram for a specific
image a viewer will be able to judge the entire tonal
distribution at a glance." - Image histogram.
– Histogram is a graphical representation of the intensity
distribution of an image.
– Histogram quantifies the number of pixels for each
intensity value.
Histograms
• Goal
• In this section,
• We will learn the concepts of histogram equalization and use it to
improve the contrast of our images.
• Theory
• Consider an image whose pixel values are confined to some specific range
of values only. For eg, brighter image will have all pixels confined to high
values. But a good image will have pixels from all regions of the image. So
you need to stretch this histogram to either ends (as given in below
image, from wikipedia) and that is what Histogram Equalization does (in
simple words). This normally improves the contrast of the image.
• import cv2
• import numpy as np
• from matplotlib import pyplot as plt
• img = cv2.imread('wiki.jpg',0)
• hist,bins = np.histogram(img.flatten(),256,[0,256])
• cdf = hist.cumsum()
• cdf_normalized = cdf * hist.max()/ cdf.max()
• plt.plot(cdf_normalized, color = 'b')
• plt.hist(img.flatten(),256,[0,256], color = 'r')
• plt.xlim([0,256])
• plt.legend(('cdf','histogram'), loc = 'upper left')
• plt.show()
Next task
• Input Output

lena.jpg
problem
• What does this program do?
– Loads an image
– Convert the original image to grayscale
– Equalize the Histogram by using the OpenCV
function cv::equalizeHist
– Display the source and equalized images in a
window.
• from __future__ import print_function
• import cv2 as cv
• import argparse
• parser = argparse.ArgumentParser(description='Code for Histogram Equalization tutorial.')
• parser.add_argument('--input', help='Path to input image.', default='lena.jpg')
• args = parser.parse_args()
• src = cv.imread(cv.samples.findFile(args.input))
• if src is None:
• print('Could not open or find the image:', args.input)
• exit(0)
• src = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
• dst = cv.equalizeHist(src)
• cv.imshow('Source image', src)
• cv.imshow('Equalized Image', dst)
• cv.waitKey()
Histogram Comparison
• Goal
• In this tutorial you will learn how to:
– Use the function cv::compareHist to get a
numerical parameter that express how well two
histograms match with each other.
– Use different metrics to compare histograms
• from __future__ import print_function
• from __future__ import division
• import cv2 as cv
• import numpy as np
• import argparse
• parser = argparse.ArgumentParser(description='Code for Histogram Comparison tutorial.')
• parser.add_argument('--input1', help='Path to input image 1.')
• parser.add_argument('--input2', help='Path to input image 2.')
• parser.add_argument('--input3', help='Path to input image 3.')
• args = parser.parse_args()
• src_base = cv.imread(args.input1)
• src_test1 = cv.imread(args.input2)
• src_test2 = cv.imread(args.input3)
• if src_base is None or src_test1 is None or src_test2 is None:
• print('Could not open or find the images!')
• exit(0)
• hsv_base = cv.cvtColor(src_base, cv.COLOR_BGR2HSV)
• hsv_test1 = cv.cvtColor(src_test1, cv.COLOR_BGR2HSV)
• hsv_test2 = cv.cvtColor(src_test2, cv.COLOR_BGR2HSV)
• hsv_half_down = hsv_base[hsv_base.shape[0]//2:,:]
• h_bins = 50
• s_bins = 60
• histSize = [h_bins, s_bins]
• # hue varies from 0 to 179, saturation from 0 to 255
• h_ranges = [0, 180]
• s_ranges = [0, 256]
• ranges = h_ranges + s_ranges # concat lists
• # Use the 0-th and 1-st channels
• channels = [0, 1]
• hist_base = cv.calcHist([hsv_base], channels, None, histSize, ranges, accumulate=False)
• cv.normalize(hist_base, hist_base, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
• hist_half_down = cv.calcHist([hsv_half_down], channels, None, histSize, ranges, accumulate=False)
• cv.normalize(hist_half_down, hist_half_down, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
• hist_test1 = cv.calcHist([hsv_test1], channels, None, histSize, ranges, accumulate=False)
• cv.normalize(hist_test1, hist_test1, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
• hist_test2 = cv.calcHist([hsv_test2], channels, None, histSize, ranges, accumulate=False)
• cv.normalize(hist_test2, hist_test2, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
• for compare_method in range(4):
• base_base = cv.compareHist(hist_base, hist_base, compare_method)
• base_half = cv.compareHist(hist_base, hist_half_down, compare_method)
• base_test1 = cv.compareHist(hist_base, hist_test1, compare_method)
• base_test2 = cv.compareHist(hist_base, hist_test2, compare_method)
• print('Method:', compare_method, 'Perfect, Base-Half, Base-Test(1), Base-Test(2) :',\
• base_base, '/', base_half, '/', base_test1, '/', base_test2)
• We use as input the following images:
– where the first one is the base (to be compared to
the others), the other 2 are the test images.
– We will also compare the first image with respect
to itself and with respect of half the base image.
• We should expect a perfect match when we
compare the base image histogram with itself.
Also, compared with the histogram of half the
base image, it should present a high match
since both are from the same source. For the
other two test images, we can observe that
they have very different lighting conditions, so
the matching should not be very good:
• Here the numeric results we got with OpenCV :
To run this code
• E:\Galgotias-University\Winter-
2020\DIP\program>python Hcomparisin.py
--input1 Source_0.jpg --input2 Source_1.jpg
--input3 Source_2.jpg
output

*Method* Base - Base Base - Half Base - Test 1 Base - Test 2


*Correlation* 1.000000 0.880438 0.20457 0.0664547
*Chi-square* 0.000000 4.6834 2697.98 4763.8
*Intersection* 18.8947 13.022 5.44085 2.58173
*Bhattacharyya
* 0.000000 0.237887 0.679826 0.874173

You might also like