0% found this document useful (0 votes)
36 views5 pages

Dip Lab-5

This document discusses techniques for image enhancement, including gray-level slicing, histogram equalization, and contrast stretching. Students are expected to complete exercises applying each technique to an image and submitting the results. Gray-level slicing highlights intensity ranges. Histogram equalization redistributes intensities for uniform distribution. Contrast stretching linearly maps intensities to improve image contrast.

Uploaded by

Golam Daiyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Dip Lab-5

This document discusses techniques for image enhancement, including gray-level slicing, histogram equalization, and contrast stretching. Students are expected to complete exercises applying each technique to an image and submitting the results. Gray-level slicing highlights intensity ranges. Histogram equalization redistributes intensities for uniform distribution. Contrast stretching linearly maps intensities to improve image contrast.

Uploaded by

Golam Daiyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CSE 440 Digital Image Processing Lab-6

Gray intensity slicing, histogram equalization and contrast stretching.

Name: _________________________________

Enrollment #: _________________________________

Class: _________________________________

Objective

The purpose of today’s lab is to have an insight into the gray intensity slicing,
histogram equalization and contrast stretching.

Submission Requirements

You are expected to complete the assigned tasks within the lab session and show them to
the lab engineer/instructor. Get the lab journal signed by your instructor and submit it by the
end of lab session.

Gray-Level Slicing

Highlighting a specific band (or range) of gray-intensities in an image is referred as gray-level


slicing. The purpose of gray-level slicing is to assign more weight to certain
details/information in an image for the purpose of analysis or to make them more visible in an
image. Examples of typical gray level slicing can be seen in the following figure.

Figure 1: Gray level slicing transformations


The following two exercises will help you better understand the concept of gray level slicing.

Exercise 1

Consider a function f(x) defined over an image ‘cameraman.tif’ with the intensities in
the range [0 1], as defined below:

a) Draw a graph for f(x) to show its influence on image intensities.

b) Write a Python program to implement f(x) on an input image. Also, show


your result after transformation.

Exercise 2

Write a MATLAB program for the following function on an input image ‘cameraman.png’.
Also show your result.

Hints:
1. Convert the given graph into a Mathematical function.
2. Find equation of line for x>0.5.

This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00

https://www.coursehero.com/file/98215667/Journal-06pdf/
Histogram Equalization
Histogram equalization is the process of re-allocating intensity values of the pixels in an image such that
the output image contains uniform distribution of intensities defined by a monotonically increasing
function T(r).

Function in Python:
cv2.equalizeHist(gray): equalizes histogram of an input image in_img for the specified gray
levels L.

How to Equalize a Histogram?

Algorithm to Equalize an Image Histogram

This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00

https://www.coursehero.com/file/98215667/Journal-06pdf/
Exercise 3
Write a function named ‘myhist_equ’ to MANUALLY equalize histogram of an
image ‘cameraman.png’ and map corresponding results:

INPUTS: image

OUTPUTS: Display the input image as well as equalized (resultant) image along
with histogram before and after histogram equalization.

Note: Do not use the cv2.equalizeHist() function in Python Load the


image ‘person.png’ and display the output as illustrated in Figure 2.

Figure 2:Histogram Equalization

Contrast Stretching
Contrast stretching attempts to improve an image by stretching the range of intensity values it contains
to make full use of possible values. Unlike histogram equalization, contrast stretching is restricted to a
linear mapping of input to output values. The result is less dramatic, but tends to avoid the sometimes
artificial appearance of equalized images.

For each pixel, the original value r is mapped to output value s using the function:

Where rmin and rmax represent the minimum and the maximum gray values in the image, L-1
represents the maximum gray level in the image (for 8 bit images, L-1 = 255).

From the view point of implementation, convert the image to double, hence the factor L-1 = 1.

This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00

https://www.coursehero.com/file/98215667/Journal-06pdf/
Exercise 4

Write a function named ‘constrastStretch’ to stretch the contrast of an image.

INPUTS: image

OUTPUTS: Display the input image as well as the contrast stretched (resultant) image
along with the histogram of each. Load the image ‘person.png’ and display the output
as illustrated in Figure 3.

Figure 3:Contrast Stretching

This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00

Powered by TCPDF (www.tcpdf.org)


https://www.coursehero.com/file/98215667/Journal-06pdf/

You might also like