Lesson4 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Preprocessing

n Duration: 3 hr
n Outline:
1. Introduction to Matlab
2. Fundamentals
3. Spatial domain processing
4. Frequency domain processing
Preprocessing

n Duration: 3 hr
n Outline:
1. Introduction to Matlab
2. Fundamentals
3. Spatial domain processing
4. Frequency domain processing
Matlab working environment

§ Matlab desktop:
Ø command window
Ø workspace
Ø command history window
Ø current directory window
Ø figure window
Ø editor window
Matlab working environment (cont)

Current directory window

Command window
workspace
Matlab working environment (cont)

Figure window
Matlab working environment (cont)

History command
window
Matlab working environment (cont)

Editor window
Basic commands and formatting
Basic commands and formatting (cont)
Basic commands and formatting (cont)
Conditional statements and loops

§ Conditional statements
Conditional statements and loops (cont)

§ Loops
Preprocessing

n Duration: 3 hr
n Outline:
1. Introduction to Matlab
2. Fundamentals
3. Spatial domain processing
4. Frequency domain processing
Digital image representation

§ Monochrome image ßà image: 2D light intensity function f(x,y)


Where (x,y): spatial coordinates
f value: brightness (or gray level) of the image at point (x,y)

origin y

x
Digital image representation

§ Digital image: be discretized in spatial coordinates and


brightness

§ Digital image: matrix, element is called picture element


(pixel)

§ Truecolor image: matrix of pixel value is a 3D array


with size M- by-N-by-3.
Image data

§ Binary: 0 and 1

§ Gray scale: black, shades of gray, white. Typically 256


quantization levels

§ Color: three primary color components, e.g RGB, HSV,


Lab, Luv, CMYK, etc.

§ Resolution: 1024x1024, 512x512, 256x256, 352x240, …


Coordinate conventions

In books In Matlab image processing toolbox


Image as matrix

origin

⎡ f (1,1) f =
f (1,2) ... f (1, N ) ⎤⎥

⎢ f (2,1) f (2,2) ... f (2, N ) ⎥
f =⎢ ⎥
⎢ ... ⎥
⎢⎣ f (M ,1) f (M ,2) ... f (M , N ) ⎥⎦
Working with images (1/2)

§ Reading an image

>> imread(‘filename’);

e.g.
Working with images (2/2)

§ Displaying an image
>> figure, imshow(im);

>> figure, imshow(im [low high]);


?
?
?
?
Preprocessing

n Duration: 3 hr
n Outline:
1. Introduction to Matlab
2. Fundamentals
3. Spatial domain processing
4. Frequency domain processing
Spatial domain processing

§ Intensity transformations (point processing)

§ Histogram processing

§ Spatial filtering
Expression of spatial domain processing

g(x,y) = T[f(x,y)]
output input
operator: defined
over a specified
neighborhood
about point (x,y)
Image f(x,y)
Intensity transformation

§ Operator T: size of neighborhood = 1x1 à point processing


§ Arithmetic operations

§ Negative

§ Contrast stretching

§ Log transformation

§ Power-law transforms
Arithmetic operations: addition, subtraction
Addition
Subtraction
Arithmetic operations: multiplication,
division
Multiplication
Division
Negative
Example of leaf segmentation
Negative

Original mammogram Negative mammogram


Contrast stretching

§ It is normally
controlled by a
piecewise linear
transformation

§ Thresholding:
r1 = r2, s1 = 0, s2
= L-1.

Contrast stretching Thresholding


Log transformation

Original image After processing c = 1


Power-law transformation

§ Plots of the
equation s = c.rγ, for
various values of γ

(c = 1 in all cases)
Power-law transformation

Original γ=3
image c=1

γ=4 γ=5
c=1 c=1
Spatial domain processing

§ Intensity transformations (point processing)

§ Histogram processing

§ Spatial filtering
Image histogram

§ Graphical representation of the lightness/color


distribution in a digital image.

§ Number of pixels per each intensity value


Examples of Dark image

image
histograms
Bright image

Low-contrast image

High-contrast image
Histogram equalization

Re-assigning the intensity values of pixels in the input image


such that the output image histogram is flat.
Contrast stretching

Histogram equalization
Contrast stretching

Histogram equalization
Spatial domain processing

§ Intensity transformations (point processing)

§ Histogram processing

§ Spatial filtering
Some typical lowpass filters
An example of image after lowpass filtering
n2

h= n1
Median filtering

§ Lowpass filters cause blurring, which is critical for


images with sharp edges, but not critical for image of
smooth contrast.

§ To avoid blurring, median filtering is a solution

§ Median filtering is a nonlinear process especially useful


for reducing impulse, or salt-and-pepper noise
Averaging mask vs. median filter

Noisy image After 3x3 After 3x3


averaging masking median filtering
Highpass filters
§ Some highpass spatial filters:

§ Note: if the result is over the range [0, L-1], need to scale
and level-shift to remain in [0, L-1]
High-boost filters
§
é- 1 - 1 - 1ù é- 1 - 1 - 1ù é0 0 0ù
1ê ú 1ê
with A ³ 1, -1 9A -1 -1 = -1 8 - 1 ú + ê0 A -1 0ú
9 ê ú 9ê ú ê ú
êë- 1 - 1 - 1úû êë- 1 - 1 - 1úû êë0 0 0 úû

Original image A = 1.1


High-boost filters
§
é- 1 - 1 - 1ù é- 1 - 1 - 1ù é0 0 0ù
1ê ú 1ê
with A ³ 1, -1 9A -1 -1 = -1 8 - 1 ú + ê0 A -1 0ú
9 ê ú 9ê ú ê ú
êë- 1 - 1 - 1úû êë- 1 - 1 - 1úû êë0 0 0 úû

A = 1.15 A = 1.2
Image after high-boost filtering
Preprocessing

n Duration: 3 hr
n Outline:
1. Introduction to Matlab
2. Fundamentals
3. Spatial domain processing
4. Frequency domain processing
Discrete Fourier Transform (DFT)
DFT in image processing
Smoothing an image by low-pass filter

§ Smoothing is achieved by dropping out the high frequency


components using low pass filters

§ Basic model: G(u,v) = H(u,v) F(u,v)

F(u,v): DFT of image, H(u,v): filter transfer function


Ideal low-pass filter
Butterworth low-pass filter
Gaussian low-pass filter
Gaussian low pass filter to connect broken text
Gaussian low pass filter to remove blemishes
Sharpening by high-pass filter

§ Sharpening is to enhance the edges and fine details in an


image.

§ Sharpening is achieved by high pass filters

§ Basic model: reverse of low pass


Matlab
§ imread

§ imshow

§ imfilter

§ conv2

§ medfilt2

§ imnoise

§ fspecial

§ dftfilt

§ freqz

§ hist

You might also like