0% found this document useful (0 votes)
74 views42 pages

Statistics and Image Processing Part 2

The document discusses image processing techniques in MATLAB, including reading, displaying, and modifying images. It covers converting between image types like RGB, grayscale, and binary. Intensity transformations are covered, including adjusting contrast and brightness using functions like imadjust, histeq, and adapthisteq. Spatial filtering concepts like neighborhoods and pixel operations are introduced.

Uploaded by

Sufiyan N-Yo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views42 pages

Statistics and Image Processing Part 2

The document discusses image processing techniques in MATLAB, including reading, displaying, and modifying images. It covers converting between image types like RGB, grayscale, and binary. Intensity transformations are covered, including adjusting contrast and brightness using functions like imadjust, histeq, and adapthisteq. Spatial filtering concepts like neighborhoods and pixel operations are introduced.

Uploaded by

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

Statistics and Image Processing

Part 2 Image Processing


Georg Fries
Content Image Processing

Content
Images in MATLAB
RGB, Grey Scale, Binary
Images and Matrices
Handling Images
Intensity Transformation
Adjusting Contrast and Brightness
Histogram
Spatial Filtering
Neighbourhood
Sharpening and Softening
Denoising
Speckle and Salt & Pepper Noise

Georg Fries Modelling and Simulation using MATLAB 2


Images in MATLAB

Images: London Eye

Georg Fries Modelling and Simulation using MATLAB 3


Images in MATLAB

It is a Matrix!

Georg Fries Modelling and Simulation using MATLAB 4


Images in MATLAB

It is a Matrix!

Georg Fries Modelling and Simulation using MATLAB 5


Images in MATLAB

Image Types
True Colour (RGB) Grey Scale Binary

Georg Fries Modelling and Simulation using MATLAB 6


Images in MATLAB

Image types
True Colour (RGB) Grey-Scale Binary

Georg Fries Modelling and Simulation using MATLAB 7


Images in MATLAB

Image Types
Grey Scale
Grey Scale
moose_gray.png
M by N matrix
Pixel values I(r,c)
specify intensity values
of monochrome image

8 bit:
uint8
0 => Black
255 => White

Georg Fries Modelling and Simulation using MATLAB 8


Images in MATLAB

Image Types
Binary
Binary
moose_bin.png
M by N matrix
Containing only
0s and 1s,
interpreted as
Black or White

1 bit: logical
0 => Black
1 => White

Georg Fries Modelling and Simulation using MATLAB 9


Images in MATLAB

Image Types
True Colour
RGB
moose.png
M by N by 3 array
Pixel values specify
intensity values of 3
monochrome images

24 bit:
uint8 x 3
0 => Black
255 => Max(R,G,B)

Georg Fries Modelling and Simulation using MATLAB 10


Images in MATLAB

True Colour

RGB Red Green Blue


Georg Fries Modelling and Simulation using MATLAB 11
Images in MATLAB

Handling Images
MATLAB func+on Descrip+on
imshow(I) Displays the image I in a Handle Graphics gure, where I is
a grey scale, RGB (true colour), or binary image
I = imread(filename,fmt) Reads a grey scale or colour image from the le "lename"

imwrite(I,filename) Writes image data I to the le "lename


Inferring the le format from the extension
Creates the new le in your current folder
info = imfinfo(I) Returns informaEon about an image in a graphics le

image Creates an image graphics object by interpreEng each


element in a matrix as an index into the gure's colour map
or directly as RGB values, depending on the data specied

Reference: hJp://www.mathworks.com/help/matlab
Georg Fries Modelling and Simulation using MATLAB 12
Images in MATLAB

Create Binary Image using im2bw


I=imread('moose_gray.png');
Grey Scale Binary
threshold = 0.55;
BW = im2bw(I, threshold);
imwrite(BW,'moose_bin.png');

Change the threshold value!

Georg Fries Modelling and Simulation using MATLAB 13


Images in MATLAB

True Colour

RGB=imread('piccadilly.jpg');
RGB(:,:,2)=0;
RGB(:,:,3)=0;
imshow(RGB) RGB=imread('piccadilly.jpg');
RGB(:,:,1)=0;
RGB(:,:,3)=0;
imshow(RGB)
RGB=imread('piccadilly.jpg');
RGB(:,:,1)=0;
RGB(:,:,2)=0;
imshow(RGB)

RGB Red Green Blue


Georg Fries Modelling and Simulation using MATLAB 14
Intensity Transformation

Intensity Transformation
Maps an image's intensity values to a new range
Pixel values are modified in intensity without
taking into account their neighbourhood
The new value depends only on the input pixel
Image structure is preserved

Adjust
Contrast
Brightness
Saturation
Colours

Georg Fries Modelling and Simulation using MATLAB 15


Intensity Transformation

Again: London Eye


eye=imread('eye_color.jpg');
imshow(eye);

Georg Fries Modelling and Simulation using MATLAB 16


Intensity Transformation

Calculate Histogram of Image Data: imhist


gray=imread('eye_gray.jpg');
imshow(gray);
figure;
imhist(gray);

Looks ne!

Georg Fries Modelling and Simulation using MATLAB 17


Intensity Transformation

Lacking in Contrast: "Dull"


dull=imread('eye_dull_gray.jpg');
imshow(dull);
figure;
imhist(dull);

No black
No white
=> Low contrast!

Georg Fries Modelling and Simulation using MATLAB 18


Intensity Transformation

Lacking in Contrast: "Light"


light=imread('eye_light_gray.jpg');
imshow(light);
figure;
imhist(light);

Too bright!

Georg Fries Modelling and Simulation using MATLAB 19


Intensity Transformation

Lacking in Contrast: "Dark"


dark=imread('eye_dark_gray.jpg');
imshow(dark);
figure;
imhist(dark);

Too dark!

Georg Fries Modelling and Simulation using MATLAB 20


Intensity Transformation

Try the "Adjust Contrast Tool" !

Georg Fries Modelling and Simulation using MATLAB 21


Intensity Transformation

Adjusting: imadjust, histeq and adapthisteq


imadjust
Increases contrast by mapping the values of the input intensity image to new
values such that 1% of the data is saturated at low and high intensities
histeq performs histogram equalization
Enhances contrast by transforming the values in an intensity image so that the
histogram of the output image approximately matches a specified histogram
Uniform distribution by default
adapthisteq performs contrast-limited adaptive histogram equalization
Operates on small data regions (tiles) rather than the entire image
Each tile's contrast is enhanced so that the histogram of each output region
approximately matches the specified histogram
Reference: hJp://www.mathworks.com/help/matlab
Georg Fries Modelling and Simulation using MATLAB 22
Intensity Transformation

dull=imread('eye_dull_gray.jpg');
imadjust b=imadjust(dull);
figure;imhist(b);

Georg Fries Modelling and Simulation using MATLAB 23


Intensity Transformation

dull=imread('eye_dull_gray.jpg');
histeq a=histeq(dull);
figure;imhist(a);

Georg Fries Modelling and Simulation using MATLAB 24


Intensity Transformation

dull=imread('eye_dull_gray.jpg');
adapthisteq c=adapthisteq(dull);
figure;imhist(c);

Georg Fries Modelling and Simulation using MATLAB 25


Spatial Filtering

Neighbourhood
Neighbourhood

Georg Fries Modelling and Simulation using MATLAB 26


Spatial Filtering

Pixel Operations

Georg Fries Modelling and Simulation using MATLAB 27


Spatial Filtering

Steps of Sliding Neighbourhood Processing


(1) Selecting a centre pixel (r,c)

(2) Performing an operation that involves only the pixels in a predefined


neighbourhood around the centre pixel (r,c)

(3) Letting the result of that operation be the response of the process at the
current pixel

(4) Repeating the process for every pixel in the image

Reference: Gonzales, Woods: Digital Image Processing using MATLAB


Georg Fries Modelling and Simulation using MATLAB 28
Spatial Filtering

Linear Spatial Filtering

Georg Fries Modelling and Simulation using MATLAB 29


Spatial Filtering

Linear Spatial Filtering: imfilter, fspecial


fspecial provides predefined 2D linear spatial filters
h=fspecial('type',parameters)
type: Average, Gaussian, Laplacian, Unsharp
imfilter applies filtering

I=imread('ladies.jpg');
% Create filter kernel
h=fspecial('unsharp');
% Apply filter to image I
Jsharp=imfilter(I,h);
imshow(Jsharp);

Georg Fries Modelling and Simulation using MATLAB 30


Spatial Filtering

Chez Tussaud
I=imread('ladies.jpg');
imshow(I)

Georg Fries Modelling and Simulation using MATLAB 31


Spatial Filtering

Softening
I=imread('ladies.jpg');
h=fspecial('average',
[11 11]);
Jsoft=imfilter(I,h);
imshow(Jsoft);

Georg Fries Modelling and Simulation using MATLAB 32


Spatial Filtering

Sharpening
I=imread('ladies.jpg');
h=fspecial('unsharp');
Jsharp=imfilter(I,h);
imshow(Jsharp);

h =

-0.1667 -0.6667 -0.1667
-0.6667 4.3333 -0.6667
-0.1667 -0.6667 -0.1667

Georg Fries Modelling and Simulation using MATLAB 33


Denoising

Denoising Images

Georg Fries Modelling and Simulation using MATLAB 34


Denoising

Adding Noise to Images: imnoise


J=imnoise(I,type)
type descrip+on
'gaussian' Gaussian white noise with
Adds noise of a given type constant mean and variance
to the image I
'localvar' Zero-mean Gaussian white
noise with an intensity-
Noise types support dependent variance
additional parameters
'poisson' Poisson noise
'salt & On and o pixels
pepper'
'speckle' MulEplicaEve noise

Reference: hJp://www.mathworks.com/help/matlab
Georg Fries Modelling and Simulation using MATLAB 35
Denoising

Speckle Noise
I=imread('metro.jpg');
J=imnoise(I,'speckle');
imshow(I);
figure; imshow(J);

Georg Fries Modelling and Simulation using MATLAB 36


Denoising

Adding Salt & Pepper Noise


I=imread('moose_gray.png');
J=imnoise(I,'salt & pepper',0.15);
imshow(I);
figure; imshow(J);

Georg Fries Modelling and Simulation using MATLAB 37


Denoising

Filtering Mean 3x3


I=imread('moose_gray.png');
J=imnoise(I,'salt & pepper',0.15);
imshow(I);
figure; imshow(J);
h=ones(3,3)/9;
K=imfilter(J,h);
figure; imshow(K);

Georg Fries Modelling and Simulation using MATLAB 38


Denoising

Georg Fries Modelling and Simulation using MATLAB 39


Denoising

Filtering: Median 3x3


I=imread('moose_gray.png');
J=imnoise(I,'salt & pepper',0.15);
imshow(I);
figure; imshow(J);
h=ones(3,3)/9;
K=imfilter(J,h);
figure; imshow(K);
L=medfilt2(J,[3 3]);
figure; imshow(L)

Georg Fries Modelling and Simulation using MATLAB 40


Denoising

Compare: Original Median

Georg Fries Modelling and Simulation using MATLAB 41


Homework

Homework

Georg Fries Modelling and Simulation using MATLAB 42

You might also like