Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
159 views

P4-Histogram Processing - Tutorial

This document discusses various techniques for modifying image histograms in MATLAB, including: - Calculating and displaying image histograms using imhist. - Performing histogram equalization to flatten histograms using histeq. - Matching histograms to a specified shape using histogram specification. - Adjusting image brightness through histogram sliding by adding/subtracting pixel values. - Using functions like adapthisteq for local histogram equalization, imadjust for brightness/contrast control, and stretchlim for histogram stretching/shrinking.

Uploaded by

yakaellah
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views

P4-Histogram Processing - Tutorial

This document discusses various techniques for modifying image histograms in MATLAB, including: - Calculating and displaying image histograms using imhist. - Performing histogram equalization to flatten histograms using histeq. - Matching histograms to a specified shape using histogram specification. - Adjusting image brightness through histogram sliding by adding/subtracting pixel values. - Using functions like adapthisteq for local histogram equalization, imadjust for brightness/contrast control, and stretchlim for histogram stretching/shrinking.

Uploaded by

yakaellah
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Histogram Processing

Image Processing
Tutorial
• Image histograms
• Histogram equalization and spesification
• Other histogram modification techniques
Image Histograms
Goal
• The goal of this tutorial is to use MATLAB and IPT to calculate and
display image histograms.
Objectives
• Learn how to use the IPT function imhist.
• Learn how other MATLAB plotting techniques can be used to view and
analyze histogram data.
Image Histograms: imhist
1. Display an image and its histogram.

2. The previous step displayed the default histogram for the image—a histogram with
256 bins. Let us see what happens if we change this value to 64 and 32.

You may have noticed that we set the axis to tight when displaying histograms.
This adjusts the axis limits to the range of the data.
Image Histograms: imhist

Question 1
Explain the drastic change of the Y-axis values when the histogram is displayed with
fewer bins.
Image Histograms: bar
3. Get the values of each bin in the histogram for later use.
• We can now use the values in c to display histogram using
other plotting techniques.
• Naturally, the plot of a histogram displays the count of each
bin, but it may be more relevant to plot each bin’s
percentage.
• This can be done by normalizing the data

4. Normalize the values in c.

Question 2
What does the function numel do?
Question 3
Write a one line MATLAB statement that will verify that the
sum of the normalized values add to 1.
Image Histograms: bar
• In MATLAB, almost every object you create can be customized.
• When we create the bar chart, there is an axes object and a bar chart object displayed on the axes object.
• Here, the variable bar_1 is set to the bar chart object so that we can reference it later for further
customization.

• The set function allows us to change settings of a particular object.


• The first parameter of the set function is the object you wish to customize. In this case, the first object we
customize is gca, which stands for get current axes.
• Here, we set the limits of the X and Y axes. Even though the limits have been set, the graph is still
ambiguous because the tick marks on the X and Y axes do not reflect the limits.
Image Histograms: The Ambiguity

VS
Image Histograms:
Customize Graph Object
5. Set the tick marks to reflect the limits of the graph.

6. Use the set function to change the color of the bar chart. Also,
give the charta title.

Question 4
How would we change the width of the bars in a bar chart?

Notice in the previous step how we used the bar chart object
bar_1 when changing settings.
Similarly, we can display the normalized bar chart on the same
figure using subplot.
Image Histograms:
Customize Graph Object
Image Histograms:
Customize Graph Object
Image Histograms: stem
• You may have noticed that we used xlim and ylim functions to set the
limits of the axes.
• Sometimes there is more than one way to accomplish the same task,
and this is an example of just that.
• Stem charts are similar to bar charts.
Image Histograms: stem
Question 5
Explore the properties of stem charts. How
can we make the lines dotted instead of
solid?

Question 6
Alter the axes limits and tick marks to reflect
the data being displayed in the stem plot.

We could have just as easily set a variable equal to the stem plot object and used the
set function to make the changes.
Image Histograms: plot
7. Display a plot graph for both standard and normalized histogram data.

The plot function will display the data by connecting each point
with a straight line.

Question 7

Explore the properties of plot graphs. In the above code, the


points for each bin are visually lost within the graph line.

How can we make the points bolder so that they are more
visible?
Histogram Equalization and Spesification
Goal
• The goal of this tutorial is to learn how to use the IPT for (global and local) histogram equalization and
histogram specification (matching).

Objectives
• Explore the process of histogram equalization.
• Learn how to use the histeq function.
• Learn how to perform histogram specification (matching).
• Explore the Interactive Histogram Matching demo.
• Learn how to perform local histogram equalization with the adapthisteq function.

What You Will Need


• ihmdemo.m—interactive Histogram Matching demo M-file
Histogram Equalization
1. Display the image pout and its histogram.

2. Use the histeq function to perform histogram equalization.

Question 1 Question 2
Why must we include the second parameter (256) in the histeqWhat is the effect of histogram equalization on
function call? images with low contrast?
Histogram Equalization
4. Execute the following code to perform histogram equalization on the tire
image.

Question 3
Based on the tire image’s original histogram, what can be said
about its overall brightness?

Question 4
How did histogram equalization affect the overall image brightness in
this case?
Histogram Equalization
Histogram equalization does not always perform well. As we will see in
the next steps, it depends on the original image.

Question 5
Why was there such a loss in image quality after histogram equalization?
Histogram Equalization: CDF
The transformation function for histogram equalization is simply the cdf of the original image.

5. Display the normalized cdf for the eight.tif image.

Question 6
What does the cumsum function do in the previous step?
Histogram Equalization: CDF
6. The transformation function can also be obtained without using the cumsum function.
Histogram Spesification
• As we have learned, the histogram equalization process attempts to flatten the
image histogram.
• Histogram specification (also known as histogram matching) tries to match the
image histogram to a specified histogram.
• The histeq function can also be used for this operation.

7. Prepare a subplot and display original image and its histogram.


Histogram Spesification
8. Display the image after histogram equalization for comparison.

9. Display matched image where the desired histogram shape is a straight line from (0, 0) to (1, 1).
Histogram Spesification

As we can see from the previous steps, performing histogram specification means
we must generate a function that represents the shape of the desired histogram.
Local histogram equalization
• Local histogram equalization is performed by the adapthisteq function.
• This function performs contrast limited adaptive histogram equalization (CLAHE)
and operates on small data regions (called tiles), whose size can be passed as a
parameter.
Contrast Limited Adaptive Histogram Equalization
(CLAHE)
Question 10
What does the ClipLimit setting do in the adapthisteq function?

Question 11
What is the default tile size when using adapthisteq?
https://www.mathworks.com/help/visionhdl/ug/contrast-adaptive-histogram-equalization.html
OTHER HISTOGRAM MODIFICATION
TECHNIQUES
Goal
• The goal of this tutorial is to learn how to perform other common histogram modification
• operations.
Objectives
• Learn how to adjust brightness of an image by histogram sliding.
• Learn how to use the imadjust function.
• Learn how to use the stretchlim function.
• Explore adjusting image contrast through histogram stretching (also known as input cropping).
• Learn how to adjust image contrast with histogram shrinking (also known as output cropping).
Histogram Sliding
• Histogram sliding is the process of adding or subtracting a constant brightness
value to all pixels in the image.
• When implementing histogram sliding, we must make sure that pixel values do
not go outside the boundaries of the gray scale.
• Therefore, any pixels that result in values greater than 1 after adjustment will be
set to 1.
• Likewise, any pixels resulting in values less than zero after adjustment will be set
to 0.
Histogram Sliding
1. Display original image and prepare subplot.

2. Obtain a brighter version of the input image by adding 0.1 to each pixel.

Question 1
How did the histogram change after the adjustment?
Histogram Sliding
3. Produce another brighter image by adding 0.5 to original image.

Question 2
What does the variable bad_values contain?

Question 3
Why does the third plot show such an excessive number of pixels with a value of 1?

“The brightness of an image can also be modified using the imadd function, which takes care
of truncating and rounding off values outside the desired range in the output image.”
Histogram Streching
Histogram stretching and shrinking can be achieved through use of the imadjust function.
The syntax for the function is as follows:
Power Law (Gamma) Transformations
Histogram Stretching
• Any values below low_in and above high_in are clipped or simply mapped to low_out and
high_out, respectively.
• Only values in between these limits are affected by the curve.
• Gamma values less than 1 create a weighted curve toward the brighter range, and gamma values
greater than 1 weight toward the darker region.
• The default value of gamma is 1.
Histogram Stretching
4. Execute the following code to see histogram stretching on the pout image, which is already loaded in
variable I.

Question 4
How did the histogram change after the adjustment?

Question 5
What is the purpose of using the stretchlim function?
Histogram Stretching
• In the previous step, we specified the low_in, high_in, low_out, and high_out parameters when
calling the imadjust function when in fact the default operation is histogram stretching—meaning
these parameters are not necessary to perform histogram stretching.
• Notice in the next step how just calling the function and only specifying the image as its parameter
will give the same results.

5. Perform histogram stretching with imadjust using default parameters and confirm that the results are
identical to the ones obtained before.

Question 6
How does the difference image look?
Question 7
What is the purpose of inspecting its maximum
and minimum values?
Histogram Shringking
To shrink an image histogram, we must specify the parameters explicitly.

6. Execute the following code to see the result of histogram shrinking.


View Transformation Function (implisitly)
• When we use other techniques to adjust the histogram of an image,
we have a means to view the transformation function (i.e., the
histeq function will return the transformation function as an output
parameter if requested).
• There is no built-in technique for viewing a transformation
function when performing histogram sliding, stretching, or shrinking,
but we can achieve a visual representation of the
transformationfunction by using the plot function.
• To do so, we specify the original image as the X values and the
adjusted image as the Y values.
View Transformation Function (implisitly)
7. Display the transformation function for the adjustment performed in the previous step.

Question 8
What do the above first two statements in the code do?

Question 9
What does the xlabel and ylabel functions do?
View Transformation Function (implisitly)
As noted earlier, gamma values other than 1 will specify the shape of the curve,
toward either the bright or the dark region.
8. Perform histogram shrinking with a gamma value of 2.

Question 10
The transformation function plot displays a gap from 0 to 12 (on the X axis) where there are no points. Why is this so?
Thanks

“HAPPY LEARNING”

You might also like