dr. z. r. ghassabi [email protected] tehran shomal university spring 2015...

118
Dr. Z. R. Ghassabi [email protected] Tehran shomal University Spring 2015 Digital Image Processing Session 3 1

Upload: deborah-stevenson

Post on 16-Jan-2016

241 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

1

Dr. Z. R. [email protected]

Tehran shomal UniversitySpring 2015

Digital Image ProcessingSession 3

Page 2: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

2

Outline

• Introduction• Digital Image Fundamentals• Intensity Transformations and Spatial Filtering• Filtering in the Frequency Domain• Image Restoration and Reconstruction• Color Image Processing • Wavelets and Multi resolution Processing• Image Compression• Morphological Operation• Object representation• Object recognition

Page 3: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Outline of Chapter 3

• Basic Intensity Transformation Functions• Negative, Log, Gamma

• Piecewise-Linear Transformation Functions• Contrast stretching, contrast slicing, bit-plane slicing

• Histogram Processing• Histogram Stretching, Histogram Shrink, Histogram Sliding, Histogram

equalization, adaptive local histogram, histogram matching, local histogram equalization, histogram statistics

• Fundamentals of Spatial Filtering• Smoothing Spatial Filters, Sharpening Spatial Filters, Combining Spatial

Enhancement Tools

Page 4: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement

• Methods– Spatial Domain:

• Linear• Nonlinear

– Frequency Domain:• Linear• Nonlinear

Page 5: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement

• Spatial Domain

, ,g x y T f x y

Page 6: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement

• Example: Image Subtraction for enhancing Differences

, , ,g x y f x y h x y

Page 7: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement

• Frequency Domain

Page 8: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Transforms

Page 9: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement in spatial Domain (Transformation)

• For 11 neighborhood: – Contrast Enhancement/Stretching/Point process

• For w w neighborhood:– Filtering/Mask/Kernel/Window/Template Processing

s T r

Page 10: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Enhancement in spatial Domain

Input gray level, r

Ou

tpu

t gr

ay le

vel,

s

Negative

Log

nth root

Identity

nth power

Inverse Log Some Basic Intensity Transformation Functions

Page 11: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Negatives

• Image Negatives: 1s L r L x0

L

y

y=L-x

Page 12: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image Negatives

Page 13: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Log Transformation

Page 14: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Log Transformation

)1(log10 xcy

c=100

L x0

y

Page 15: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Log TransformationRange Compression

Page 16: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Power-Law(Gamma) Transformations

s c r

Page 17: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Power-Law(Gamma) Transformations

Gamma Correction:

1.8 2.5r

11.8 2.5r

1.8 2.5r

Page 18: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Power-Law(Gamma) Transformations (Effect of decreasing gamma)

Original =0.6

=0.4 =0.3

Page 19: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Power-Law(Gamma) Transformations(Effect of increasing gamma)

Page 20: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Power-Law(Gamma) Transformations

• Medical Example

Page 21: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Piecewise-Linear Transformation Functions

• Contrast Stretching• Contrast slicing• Bite-Plane slicing

Page 22: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Contrast Stretching

Lxbybx

bxayax

axx

y

b

a

)(

)(

0

Lx

0 a b

ya

yb

200,30,1,2,2.0,150,50 ba yyba

y

Page 23: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Contrast stretching

Original

C. S. THR.

Page 24: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Contrast Stretching

Page 25: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Contrast Stretching

Lxbab

bxaax

ax

y

)(

)(

00

L x0 a b

2,150,50 ba

yClipping:

Page 26: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• imadjust(I, [low-in, high-in],[low-out, high-out])

low-in high-in

low-out

high-out

Output Image

Input Image

Page 27: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

چیست؟ مقدار ترین مناسب

MATLAB Tutorial

• imadjust(I, [low-in, high-in],[low-out, high-out], gamma)

• imadjust(I, [0.1, 0.7],[0, 1], gamma)

low-in high-in

low-out

high-out

Output Image

Input Image

Page 28: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• Use Min and Max gray-levels– Low-in: Double(min(I(:))/255)– max-in: Double(max(I(:))/255)

• Use stretchlim(I) imadjust(I,stretchlim(I) ,[low-out, high-out], gamma)

Page 29: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

low-in high-in

low-out

high-out

Output Image

Input Image

Y= )

Y= )

Y= )

Page 30: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Gray-level Slicing

Page 31: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Gray-level Slicing

Page 32: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Gray-level Slicing

Page 33: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Gray-level Slicing

Page 34: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Gray-level Slicing

Page 35: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane Slicing

Highlighting the contribution made to total image appearance by specific bitsSuppose each pixel is represented by 8 bitsHigher-order bits contain the majority of the visually significant dataUseful for analyzing the relative importance played by each bit of the image

Page 36: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane Slicing

Page 37: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane Slicing

The (binary) image for bit-plane 7 can be obtained by processing the input image with a thresholding gray-level transformation.

Map all levels between 0 and 127 to 0Map all levels between 129 and 255 to 255

Page 38: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane SlicingFractal Image

Page 39: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane SlicingFractal Image

Bit-plane 7 Bit-plane 6

Bit-plane 5 Bit-plane 4 Bit-plane 3

Bit-plane 2 Bit-plane 1 Bit-plane 0

Page 40: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bit-plane Slicing

Page 41: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Processing

Enhancement based on statistical Properties: Local, Global

Histogram Definition

h(rk)=nk

Where rk is the kth gray level and nk is the number of pixels in the image having gray level rk

Normalized histogram:

P(rk)=nk/n

Histogram of an image represents the relative frequency of occurrence of various gray levels in the image

Page 42: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Example

Page 43: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• Hist(double(I(:)),50)• imhist(I)

Page 44: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Examples

• Histogram Visual Meaning:– Dark– Bright– Low Contrast– High Contrast

Page 45: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Modification

• Histogram Stretching• Histogram Shrink• Histogram Sliding

Page 46: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Stretching

Stretch (I(r,c))

is the largest gray-value in the image I(r,c)

is the smallest gray-level in I(r,c)

(for an 8-bit image these are 0 and 255)

Page 47: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Stretching

Page 48: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Stretching

Page 49: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Shrinking

Shrink (I(r,c))

is the largest gray-value in the image I(r,c)

is the smallest gray-level in I(r,c)

Page 50: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Shrinking

Page 51: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Sliding

Page 52: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

PDF

بین بودن Uو xتناظر صعودی .CDFاکیدا هست تابع بودن صعودی اکیدا یعنی CDFبرای آن مشتق .PDFباید باشد صفر از بزرگتر همیشه

F: X-------->[0,1] U=F(X)

. دارد هم معکوس پس هست یک به یک تابع X=F-1(U)چون

x

1

0

CDF

U تصادفی متغیر

Page 53: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

10 ),( rrTs

10 ),(1 ssTr

Page 54: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

و همیشه x مستقل از مقدار uتوزیع آماری • و یک هست.0یکنواخت بین

• u~U(0,1)•X و یک توزیع میکند.0 های ورودی را بین

Uهیستوگرام

Page 55: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

r

1

0

CDFS=T(r)

PDFPr

منحنی زیر سطح

S~U(0,1)

Uهیستوگرام

ورودی تصویر هیستوگرام

ورودی تصویر rروشنایی

𝑠=∫0

𝑟

𝑃𝑟 (𝜌 )𝑑 𝜌

Page 56: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

r

1

0

CDFS=T(r)

PDFPr

ورودی تصویر rروشنایی

ورودی تصویر هیستوگرام

h 𝑖𝑠𝑡𝑜𝑔𝑟𝑎𝑚 :(𝑟 𝑗 ,𝑛 𝑗)

Pr {𝑟=𝑟 𝑗 }=𝑛 𝑗

𝑛𝑆 𝑗=∑

𝑘=0

𝑗 𝑛 𝑗

𝑛≤ 1

Page 57: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

Page 58: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

Page 59: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• histeq(I)

Page 60: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Equalization

Page 61: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Adaptive Contrast Enhancement (ACE)

𝐴𝐶𝐸=𝑘1[ 𝑚𝐼 (𝑟 , 𝑐 )

𝜎𝐿 (𝑟 ,𝑐) ] [ 𝐼 (𝑟 ,𝑐 ) −𝑚𝐿(𝑟 ,𝑐 )]+𝑘2(𝑚𝐿(𝑟 ,𝑐 ))

𝑚𝐿 (𝑟 ,𝑐 ) :𝑚𝑒𝑎𝑛 𝑓𝑜𝑟 𝑡 h𝑒𝑒𝑛𝑡𝑖𝑟𝑒𝑖𝑚𝑎𝑔𝑒 𝐼 (𝑟 ,𝑐 )

: Local standard Deviation (in the window under consideration)

= Local mean (average mean in the window under consideration)

Page 62: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Adaptive Contrast Enhancement (ACE)

Page 63: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Adaptive Contrast Enhancement (ACE)

Page 64: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• I2=adapthisteq( I,'clipLimit',0.015,'Distribution','rayleigh');

clear all;close all;clc; [f1, pp1] = uigetfile('*.jpg', 'Pick a image');I1Name = sprintf('%s%s',pp1,f1); I=imread(I1Name); if ndims(I)==3 I1=rgb2gray(I);end I2=adapthisteq( I1,'clipLimit',0.015,'Distribution','rayleigh'); figure(); subplot(1,2,1); imshow(I1); subplot(1,2,2); imshow(I2);

Page 65: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1
Page 66: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Adaptive Histogram Equalization

Page 67: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Matchingpr

pz

𝜇

exp (Histeq(I,hgram)

exp (

Page 68: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram matching:Obtain the histogram of the given image, s=T(r)

Precompute a mapped level Sk for each level rk

Obtain the transformation function G from the given pz(z)

Precompute Zk for each value of rk

Map rk to its corresponding level Sk; then map level Sk into the final level Zk

Histogram Matching

1,...,2,1,0 )],([1 LkrTGz kk

r

S

0

CDFS=T(r)PDF

Pr

rهیستوگرام تصویر ورودی

0

pz

هیستوگرام دلخواه

1,...,2,1,0 ,)()1()(0

LkszpLzG k

k

iizk

1,...,2,1,0 ,)1()()1()(00

Lkn

nLrpLrTs

k

j

jk

jjrkk

Page 69: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Matching (Specification)

هیستوگرام طوری تبدیل شود که دارای مقادیر مشخص شده 64*64برای یک تصویر باشد. bدر شکل

Page 70: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram Matching (Specification)

S0=1 , G(z3)=1, s0--- >z3هر پیکسلی که مقدارش در تصویر تعدیل هیستوگرام یک هست

.به مقداری برابر سه در هیستوگرام مشخص شده نگاشت می شود

Page 71: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image is dominated by large, dark areas, resulting in a histogram characterized by a large concentration of pixels in pixels in the dark end of the gray scale

Histogram Matching (Specification)

Page 72: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Notice that the output histogram’s low end has shifted right toward the lighter region of the gray scale as desired.

Histogram Matching (Specification)

Page 73: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Desired

Initial CDF Modified CDF

Histogram Matching (Specification)

Page 74: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Local Histogram Processing

a) Original image b) global histogram equalization c) local histogram equalization using 7x7 neighborhood.

Page 75: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Histogram using a local 3*3 neighborhood

Local Histogram Processing

Page 76: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Use of histogram statistics for image enhancement:r denotes a discrete random variable

P(ri) denotes the normalized histogram component corresponding to the i th value of r

Mean:

The nth moment:

The second moment:

1

0

)(L

iii rprm

1

0

)()()(L

ii

nin rpmrr

1

0

22 )()()(

L

iii rpmrr

Using Histogram Statistics

Page 77: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Global enhancement: The global mean and variance are measured over an entire image

Local enhancement: The local mean and variance are used as the basis for making changes

Using Histogram Statistics

rs,t is the gray level at coordinates (s,t) in the neighborhood

P(rs,t) is the neighborhood normalized histogram component

mean:

local variance:

xy

xySts

tstsS rprm),(

,, )(

xy

xyxySts

tsStsS rpmr),(

,2

,2 )(][

Page 78: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Mapping:

E,K0,K1,K2 are specified parameters

MG is the global mean

DG is the global standard deviation

Using Histogram Statistics

0 1 2. , , ,,

, .S G G S GE f x y m x y K M and k D x y k D

g x yf x y OW

Page 79: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

• A SEM sample images:

Using Histogram Statistics

Page 80: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Local Mean Local Var E or one

Using Histogram Statistics

Page 81: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

• Enhanced Images:

Using Histogram Statistics

Page 82: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Fundamental of Spatial Filtering

Page 83: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Fundamental of Spatial Filtering

The Mechanics of Spatial Filtering:

)1,1()1,1(

),1()0,1(

),()0,0(

),1()0,1(

)1,1()1,1(),(

yxfw

yxfw

yxfw

yxfw

yxfwyxg

a

as

b

bt

tysxftswyxg ),(),(),( -a

+a

-b +b

Image size: M×N, x= 0,1,2,…,M-1 and y= 0,1,2,…,N-1Mask size: m×n, a=(m-1)/2 and b=(n-1)/2

Correlation

Page 84: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Fundamental of Spatial Filtering

Page 85: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Spatial Correlation and Convolution

Page 86: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Spatial Correlation and Convolution

Page 87: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

9

1

992211

...

iii zw

zwzwzwR

Vector Representation of Linear FilteringVector Representation of Linear Filtering

Page 88: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Smoothing Linear Filters :Noise reductionSmoothing of false contoursReduction of irrelevant detail

9

19

1

iizR

Smoothing Spatial Filters

a

as

b

bt

a

as

b

bt

tsw

tysxftswyxg

),(

),(),(),(

Page 89: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Image smoothing with masks of various sizes.

Smoothing Spatial Filters

Page 90: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Smoothing Spatial FiltersSmoothing Spatial Filters

Page 91: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• W=repmat(1/9,3,3);• W=1/9*ones(3,3);

• a=2;• W=ones(2*a+1)• W=W/sum(W(:));

• Img1=imread(‘image1.jpg’);• Img2=imfilter(Img1,W);

Page 92: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

• Img2=imfilter(Img1,W,’symmetric’);

Page 93: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Order-statistic filters:Max

Min

Median filter: Replace the value of a pixel by the median of the gray levels in the neighborhood of that pixel

Noise-reduction

Order-Static (Nonlinear) Filters

Page 94: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Median Filter

Page 95: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

The first-order derivative:

The second-order derivative

)()1( xfxfx

f

)(2)1()1(2

2

xfxfxfx

f

Sharpening Spatial Filters

Zero in flat regionNon-zero at start of step/ramp regionNon-zero along ramp

Zero in flat regionNon-zero at start/end of step/ramp regionZero along ramp

Page 96: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Sharpening Spatial Filters

Page 97: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Sharpening Spatial Filters

Page 98: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Use of second derivatives for enhancement-The Laplacian:Development of the method

),(2),1(),1(2

2

yxfyxfyxfx

f

2

2

2

22

y

f

x

ff

),(2)1,()1,(2

2

yxfyxfyxfy

f

Sharpening Spatial Filters

2 1, , 1 1, , 1 4 ,f f x y f x y f x y f x y f x y

Page 99: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Sharpening Spatial Filters

Practically use:

Page 100: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

2

2

, ,,

, ,

f x y f x y signg x y

f x y f x y sign

0 1 0

1 5 1 90

0 1 0

isotropic

1 1 1

1 9 1 45

1 1 1

isotropic

Sharpening Spatial Filters

0 1 0

1 4 1 90

0 1 0

isotropic

1 1 1

1 8 1 45

1 1 1

isotropic

Page 101: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Sharpening Spatial Filters

2

2

, ,,

, ,

f x y f x y signg x y

f x y f x y sign

Page 102: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Sharpening Spatial FiltersTwo L. Mask

SEM image

a. Mask Result b. Mask Result

(Sharper)

Page 103: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Unsharp maskingSubtract a blurred version of an image from the image itself

f(x,y) : The image, fN (x,y): The blurred image

High boost Filtering:

),(),(),( yxfyxfyxgmask

),(*),(),( yxgkyxfyxg mask 1, k

),(*),(),( yxgkyxfyxg mask 1, k

Unsharp Masking and Highboost Filtering

Page 104: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Unsharp Masking and Highboost Filtering

Page 105: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

2

2

, ,,

, , , , 1

, 1 , ,

, ,HB

HB

HB S

Af x y f x

f x y Af x y f x y A

f x y A

y signf x y

Af x y f x y sig

f x y f x y

n

Unsharp Masking and Highboost Filtering

Page 106: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Original Laplacian (A=0)

Laplacian (A=1) Laplacian (A=1.7)

Unsharp Masking and Highboost Filtering

Page 107: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Using first-order derivatives for (nonlinear) image sharpening, The gradient:The gradient:

The magnitude is rotation invariant (isotropic)

y

fx

f

g

g

y

xf

2

122

21

22

)(mag),(

y

f

x

f

GGyxM yxf

yx ggyxM ),(

Using First-Order Derivative for (Nonlinear) Image Sharpening - The Gradient

Page 108: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Roberts Cross Gradient

Sobel

(2 1 for prewitt)

)( 59 zzg x )( 68 zzg y and

21

268

259 )()(),( zzzzyxM

6859),( zzzzyxM

Page 109: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Using the Gradient for Image Sharpening

Sobel Gradient

Page 110: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Bone Scan Laplacian

Original +Laplacian Soble of

Original

Combining Spatial Enhancement Tools

Page 111: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Smoothed Sobel (Orig. + L.)*S.Sobel

Orig.+

(Orig. + L.)*S.SobelApply Power-Law

Combining Spatial Enhancement Tools

Page 112: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

• Img0=im2double(img0);

• w=fspecial(type, parameters)• W=fspecial(‘disk’,3);• W=fspecial(‘gaussian’,101,10);• W=fspecial(‘laplacian’,0);• W=fspecial(‘log’,10,1);

• Img1=imfilter(Img0,W);• figure();imshow(normalize(Img1));• C=-1; figure();imshow(img0+C*Img1);

• Wp=fspecial(‘prewitt’); Ws=fspecial(‘prewitt’);• Img1=imfilter(Img0,Wp); Img2=imfilter(Img0,Ws);

• W=0.3*Wp+0.7*Ws; Img1=imfilter(Img0,W);

• Img1=imfilter(Img0,Wp); Img2=imfilter(Img0,Wp’);• Imshow(sqrt(Img1.^2+Img2.^2)

MATLAB Tutorial

Page 113: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

function XN=Normalize(X) Xmin=min(X(:)); Xmax=max(X(:)); XN=((X-Xmin)/(Xmax-Xmin)).^beta;end

MATLAB Tutorial

Page 114: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Img0=im2double(imread(‘….’));M=3;N=5;Domain=ones(M,N);Img1=ordfilt2(img0,M*N, Domain);Img2=ordfilt2(img0,0, Domain);Img3=ordfilt2(img0,(M+N+1)/2, Domain);

figure(); subplot(1,3,1); imshow(Img1);subplot(1,3,2); imshow(Img2);subplot(1,3,3); imshow(Img3);

MATLAB Tutorial

Page 115: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

Img0=im2double(imread(‘….’));M=3;N=5;Domain=ones(M,N);Img1=imnoise(img0,’salt & pepper’);Img2=ordfilt2(img1,(M+N+1)/2, Domain);Img3=medfilt2(img1,[M N]);

figure(); subplot(2,2,1); imshow(Img0);subplot(2,2,2); imshow(Img1);subplot(2,2,3); imshow(Img2);subplot(2,2,3); imshow(Img3);

MATLAB Tutorial

Page 116: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial• MATLAB Command:

– Image Statistics:• means2, std2, corr2, imhist, regionprops

– Image Intensity Adjustment:• imadjust, histeq, adapthisteq, imnoise

– Linear Filter:• imfilter, fspecial, conv2, corr2,

– Nonlinear filter:• medfilt2, ordfilt2,

Page 117: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

MATLAB Tutorial

Page 118: Dr. Z. R. Ghassabi z.r.ghassabi@gmail.com Tehran shomal University Spring 2015 z.r.ghassabi@gmail.com Digital Image Processing Session 3 1

End of Session 3