33
Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

  • Upload
    others

  • View
    20

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Digital Image Processing

Lecture 4(Image enhancement in spatial domain)

Bu-Ali Sina UniversityComputer Engineering Dep.

Fall 2016

Page 2: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

OutlineImage Enhancement in Spatial Domain

– Histogram based methods• Histogram Equalization• Histogram Specification• Local Histogram

– Spatial Filtering• Smoothing Filters• Median Filter• Sharpening• High Boost filter• Derivative filter

Page 3: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Image Preprocessing

Enhancement Restoration

SpatialDomain

SpectralDomain

Point Processing• >>imadjust• >>histeq

Spatial filtering• >>filter2

Filtering• >>fft2/ifft2• >>fftshift

• Inverse filtering• Wiener filtering

Page 4: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016
Page 5: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Image Enhancement (Histogram-based methods)

· The histogram of a digital image with grayvalues is thediscrete function :

· The function represents the fraction of the total number of pixelswith grayvalue .

· Histogram provides a global description of the appearance of the image.

· If we consider the grayvalues in the image as realizations of a random variable R,with some probability density, histogram provides an approximation to thisprobability density. In other words :

Page 6: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Some typical Histograms· The shape of a histogram provides useful information forcontrast enhancement.

Page 7: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Histogram-based methods)Some typical Histograms

Page 8: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Some typical Histograms

Page 9: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Histogram Equalization

· Let us assume for the moment that the input image to be enhanced hascontinuous grayvalues, with r = 0 representing black and r = 1 representing white.· We need to design a grayvalue transformation s = T(r), based on the histogram ofthe input image, which will enhance the image.· As before, we assume that:

T(r) is a monotonically increasing function for(preserves order from black to white)

T(r) maps [0,1] into [0,1] (preserves the range of allowed

grayvalues).

Page 10: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Let us denote the inverse transformation by . We assume that theinverse transformation also satisfies the above two conditions.· We consider the grayvalues in the input image and output image as random

variables in the interval [0, 1].· Let and denote the probability density of the grayvalues in theinput and output images.· If and T(r) are known, and satisfies condition 1, we can write(result from probability theory):

· One way to enhance the image is to design a transformation T(.) such thatthe grayvalues in the output is uniformly distributed in [0, 1], i.e.

· In terms of histograms, the output image will have all grayvalues in “equalproportion.”

· This technique is called histogram equalization.

Histogram Equalization

Page 11: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Consider the transformation :

· Note that this is the cumulative distribution function (CDF) of andsatisfies the previous two conditions.· From the previous equation and using the fundamental theorem of calculus

:

· Therefore, the output histogram is given by :

· The output probability density function is uniform, regardless of the input.

Histogram Equalization

Page 12: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Histogram Equalization

Page 13: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Thus, using a transformation function equal to the CDF of inputgrayvalues r, we can obtain an image with uniform grayvalues.

· This usually results in an enhanced image, with an increase in the dynamic rangeof pixel values.

· Example: Read example in page 176 of text.· For images with discrete grayvalues, we have

L: Total number of graylevelsnk: Number of pixels with grayvalue rkn: Total number of pixels in the image

· The discrete version of the previous transformation based on CDF is given by:

Histogram Equalization

Page 14: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

Example :· Consider an 8-level 64 x 64 image with grayvalues (0, 1, …, 7). The normalized

grayvalues are (0, 1/7, 2/7, …, 1). The normalized histogram is given below:

Histogram Equalization

Page 15: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Applying the previous transformation, we have (after roundingoff to nearest graylevel):

Histogram Equalization

Page 16: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Notice that there are only five distinct graylevels --- (1/7, 3/7, 5/7, 6/7, 1) in theoutput image. We will relabel them as(s0, s1, …, s4).· With this transformation, theoutput image will have histogram:

· Note that the histogram of outputimage is only approximately, andNot exactly, uniform. This shouldnot be surprising, since there is noresult that claims uniformity in thediscrete case.

Histogram Equalization

Page 17: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

Example :Histogram Equalization

Page 18: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Histogram equalization may not always produce desirable results, particularly ifthe given histogram is very narrow. It can produce false edges and regions. It canalso increase image “graininess” and “patchiness.”

Histogram Equalization

Page 19: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

o Histogram equalization yields an image whose pixels are (in theory) uniformlydistributed among all graylevels.o Sometimes, this may not be desirable. Instead, we may want a transformationthat yields an output image with a prespecified histogram. This technique is calledhistogram specification.o Again, we will assume, for the moment, continuous grayvalues.o Suppose, the input image has probability density . We want to find atransformation z = H(r) , such that the probability density of the new imageobtained by this transformation is , which is not necessarily uniform.o First apply the transformation

o This gives an image with a uniform probability density.o If the desired output image were available, then the following transformationwould generate an image with uniform density:

Histogram Specification

Page 20: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

oIt then follows from these two equations that G(z)=T(r) and, therefore, that z mustsatisfy the condition

o For discrete graylevels, we have :

Histogram Specification

Page 21: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

Example :Consider the previous 8-graylevel 64 x 64 image histogram:

Histogram Specification

Page 22: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· It is desired to transform this image into a new image, using atransformation , with histogram as specifiedbelow:

Histogram Specification

Page 23: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· The transformation T(r) was obtained earlier (reproduced below):

Histogram Specification

Page 24: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Next we compute the transformation G as before :Histogram Specification

Page 25: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Notice that G is not invertible. But we will do the best possible bysetting :

Histogram Specification

Page 26: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Combining the two transformation T and G-1, we get our requiredtransformation H :

Histogram Specification

Page 27: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Applying the transformation H to the original image yields animage with histogram as below:

Histogram Specification

Page 28: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

· Again, the actual histogram of the output image does not exactlybut only approximately matches with the specified histogram. Thisis because we are dealing with discrete histograms.

Histogram Specification

Page 29: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)

Example :Histogram Specification

Page 30: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Histogram Specification

Page 31: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Histogram Specification

Page 32: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Histogram Specification

Page 33: Digital Image Processing Lecture 4 - basu.ac.ir · Digital Image Processing Lecture 4 (Image enhancement in spatial domain) Bu-Ali Sina University Computer Engineering Dep. Fall 2016

Chapter 3: Image Enhancement (Histogram-based methods)Histogram Specification