dr. z. r. ghassabi z.r.ghassabi@gmail.com tehran shomal university spring 2015...

Post on 16-Jan-2016

239 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Dr. Z. R. Ghassabiz.r.ghassabi@gmail.com

Tehran shomal UniversitySpring 2015

Digital Image ProcessingSession 3

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

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

Image Enhancement

• Methods– Spatial Domain:

• Linear• Nonlinear

– Frequency Domain:• Linear• Nonlinear

Image Enhancement

• Spatial Domain

, ,g x y T f x y

Image Enhancement

• Example: Image Subtraction for enhancing Differences

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

Image Enhancement

• Frequency Domain

Image Transforms

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

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

Image Negatives

• Image Negatives: 1s L r L x0

L

y

y=L-x

Image Negatives

Log Transformation

Log Transformation

)1(log10 xcy

c=100

L x0

y

Log TransformationRange Compression

Power-Law(Gamma) Transformations

s c r

Power-Law(Gamma) Transformations

Gamma Correction:

1.8 2.5r

11.8 2.5r

1.8 2.5r

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

Original =0.6

=0.4 =0.3

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

Power-Law(Gamma) Transformations

• Medical Example

Piecewise-Linear Transformation Functions

• Contrast Stretching• Contrast slicing• Bite-Plane slicing

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

Contrast stretching

Original

C. S. THR.

Contrast Stretching

Contrast Stretching

Lxbab

bxaax

ax

y

)(

)(

00

L x0 a b

2,150,50 ba

yClipping:

MATLAB Tutorial

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

low-in high-in

low-out

high-out

Output Image

Input Image

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

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

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)

MATLAB Tutorial

low-in high-in

low-out

high-out

Output Image

Input Image

Y= )

Y= )

Y= )

Gray-level Slicing

Gray-level Slicing

Gray-level Slicing

Gray-level Slicing

Gray-level Slicing

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

Bit-plane Slicing

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

Bit-plane SlicingFractal Image

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

Bit-plane Slicing

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

Histogram Example

MATLAB Tutorial

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

Histogram Examples

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

Histogram Modification

• Histogram Stretching• Histogram Shrink• Histogram Sliding

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)

Histogram Stretching

Histogram Stretching

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)

Histogram Shrinking

Histogram Sliding

Histogram Equalization

PDF

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

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

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

x

1

0

CDF

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

Histogram Equalization

10 ),( rrTs

10 ),(1 ssTr

Histogram Equalization

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

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

Uهیستوگرام

Histogram Equalization

r

1

0

CDFS=T(r)

PDFPr

منحنی زیر سطح

S~U(0,1)

Uهیستوگرام

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

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

𝑠=∫0

𝑟

𝑃𝑟 (𝜌 )𝑑 𝜌

Histogram Equalization

r

1

0

CDFS=T(r)

PDFPr

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

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

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

Pr {𝑟=𝑟 𝑗 }=𝑛 𝑗

𝑛𝑆 𝑗=∑

𝑘=0

𝑗 𝑛 𝑗

𝑛≤ 1

Histogram Equalization

Histogram Equalization

MATLAB Tutorial

• histeq(I)

Histogram Equalization

Adaptive Contrast Enhancement (ACE)

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

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

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

: Local standard Deviation (in the window under consideration)

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

Adaptive Contrast Enhancement (ACE)

Adaptive Contrast Enhancement (ACE)

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);

Adaptive Histogram Equalization

Histogram Matchingpr

pz

𝜇

exp (Histeq(I,hgram)

exp (

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

Histogram Matching (Specification)

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

Histogram Matching (Specification)

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

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

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)

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

Histogram Matching (Specification)

Desired

Initial CDF Modified CDF

Histogram Matching (Specification)

Local Histogram Processing

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

Histogram using a local 3*3 neighborhood

Local Histogram Processing

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

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 )(][

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

• A SEM sample images:

Using Histogram Statistics

Local Mean Local Var E or one

Using Histogram Statistics

• Enhanced Images:

Using Histogram Statistics

Fundamental of Spatial Filtering

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

Fundamental of Spatial Filtering

Spatial Correlation and Convolution

Spatial Correlation and Convolution

9

1

992211

...

iii zw

zwzwzwR

Vector Representation of Linear FilteringVector Representation of Linear Filtering

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

),(

),(),(),(

Image smoothing with masks of various sizes.

Smoothing Spatial Filters

Smoothing Spatial FiltersSmoothing Spatial Filters

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);

MATLAB Tutorial

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

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

Median Filter

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

Sharpening Spatial Filters

Sharpening Spatial Filters

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

Sharpening Spatial Filters

Practically use:

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

Sharpening Spatial Filters

2

2

, ,,

, ,

f x y f x y signg x y

f x y f x y sign

Sharpening Spatial FiltersTwo L. Mask

SEM image

a. Mask Result b. Mask Result

(Sharper)

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

Unsharp Masking and Highboost Filtering

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

Original Laplacian (A=0)

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

Unsharp Masking and Highboost Filtering

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

Roberts Cross Gradient

Sobel

(2 1 for prewitt)

)( 59 zzg x )( 68 zzg y and

21

268

259 )()(),( zzzzyxM

6859),( zzzzyxM

Using the Gradient for Image Sharpening

Sobel Gradient

Bone Scan Laplacian

Original +Laplacian Soble of

Original

Combining Spatial Enhancement Tools

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

Orig.+

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

Combining Spatial Enhancement Tools

• 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

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

MATLAB Tutorial

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

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

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,

MATLAB Tutorial

End of Session 3

top related