lecture 03 - chap2 point processes revised 20140210.pptfit.mta.edu.vn/files/danhsach/lecture 03 -...

Post on 23-Jul-2020

10 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CHAPTER 2CHAPTER 2

Digital Image Processing 1

POINT PROCESSESPOINT PROCESSES

Slides courtesy of Prof. Soo-Jin Lee, Paichai Univ.

Digital Image Processing

Digital Image ProcessingSlides from CS232, Stanford.

Digital Image ProcessingSlides from CS232, Stanford.

Digital Image Processing 5Slides from CS232, Stanford.

IntroductionIntroductionIntroductionIntroduction

� Point Processes vs. Area Processes

� Point processes: operate on a pixel based solely on that pixel’s value.

� Area processes: use the input pixel as well as the pixels around it to generate a new pixel.

Point processes are easily implemented as “look-up tables”.

Digital Image Processing 6

� Point processes are easily implemented as “look-up tables”.

Arithmetic OperationsArithmetic OperationsArithmetic OperationsArithmetic Operations

� Adding, subtracting, dividing, and multiplying pixels by a constant value.

Digital Image Processing 7original image

addition (+40) subtraction (-40)

multiplication (x1.2) division (/1.2)

Arithmetic OperationsArithmetic OperationsArithmetic OperationsArithmetic Operations

� Problems

� Can create negative values and values greater than the maximum possible values.

� Clamping

� Set negative values to 0.

� Set values greater than 255 to 255.

Digital Image Processing 8

� Set values greater than 255 to 255.

Arithmetic OperationsArithmetic OperationsArithmetic OperationsArithmetic Operations

� Image Subtraction and Change Detection

� medical imaging application : display blood-flow paths

� automated inspection of printed circuits

� security monitoring

Digital Image Processing 9

Arithmetic OperationsArithmetic OperationsArithmetic OperationsArithmetic Operations

Digital Image Processing 10

add operation

subtract operation

Original image

XOR OperationsXOR OperationsXOR OperationsXOR Operations

� XOR (Exclusive OR): X’Y+XY’

X Y X’Y+XY’

0 0 0

0 1 1

1 0 1

The XOR function can be used to find all pixels ofa certain value. Every pixel that is the specifiedvalue will be set to black. All other pixels will be

Digital Image Processing 11

1 1 0

original image XOR 48 XOR 128 XOR 255

value will be set to black. All other pixels will benon-black.

XOR OperationsXOR OperationsXOR OperationsXOR Operations

� The XOR function is frequently used on graphics system to generate a cursor for the mouse.

� By XORing the cursor mask with the existing pixels, the colors are changed but you can still see the shape of the image below the cursor.

� The beauty of the XOR function when superimposing is

Digital Image Processing 12

� The beauty of the XOR function when superimposing is that you need not know the value of the background to create a high contrast.

LookLook--Up TablesUp TablesLookLook--Up TablesUp Tables

7 7 5 4 2

7 6 4 3 0

7 6 4 3 1

0

0

1

• Use the current pixel value as the array index.• New value is the array element pointed by this index.

5 5 3 2 10

1

2

Digital Image Processing 13

7 6 4 3 1

6 6 4 2 0

5 5 3 1 0

1

1

2

3

4

5

2

3

4

5

6

7

Operation of a 3-bit look-up table

HistogramsHistogramsHistogramsHistograms

� A bar graph of pixel intensities.

� The pixel intensities are plotted along the x-axis and the number of occurrences (frequency) for each intensity represents the y-axis.

5

6

Digital Image Processing 14

4 4 3 3

4 4 3 3

4 1 2 3

0 1 2 3image

1

2

3

4

1 2 3 4 5 6

Pixel intensity

Fre

quency

0

HistogramsHistogramsHistogramsHistograms

Digital Image Processing 15

original imageAddition (+40) Subtraction (-40)

HistogramsHistogramsHistogramsHistograms

Digital Image Processing 16

original imagemultiplication (x1.2) division (/1.2)

HistogramsHistogramsHistogramsHistograms

Digital Image Processing 17

HistogramsHistogramsHistogramsHistograms

� RGB Color vs. Gray Images

Digital Image Processing 18

HistogramsHistogramsHistogramsHistograms

� Compression, Expansion, and Shift

(1)

Digital Image Processing 19

(a) (b)

(c) (d)

(2)

(3)

(4)

Histogram EqualizationHistogram EqualizationHistogram EqualizationHistogram Equalization

� Goal: To obtain a uniform histogram.

� Histogram equalization will NOT “flatten” a histogram.

� It redistributes intensity distributions.

� “Spreading” is a better term than “flattening” to describe histogram equalization.

Digital Image Processing 20

� Three Steps for Histogram Equalization

� Compute histogram

� Calculate normalized sum of histogram

� Transform input to output image

Digital Image Processing

Digital Image Processing

Histogram EqualizationHistogram EqualizationHistogram EqualizationHistogram Equalization

original histogram normalized sum of histogram resulting uniform histogram

Digital Image Processing 23

Histogram Equalization (Spreading)Histogram Equalization (Spreading)Histogram Equalization (Spreading)Histogram Equalization (Spreading)

Digital Image Processing 24

Histogram Equalization (HE)Histogram Equalization (HE)Histogram Equalization (HE)Histogram Equalization (HE)

� Effects of HE

� HE stretches contrast (expand the range of gray levels) for gray levels near histogram maxima.

� Compresses contrast in areas with gray levels near histogram minima.

� Contrast is expanded for the most of the image pixels.

Digital Image Processing 25

� Contrast is expanded for the most of the image pixels.

� HE usually improves detectability of many image features.

� Similar effect of enhancement could be achieved by manual contrast stretching approach, but the advantage of HE is fully automatic.

Histogram EqualizationHistogram EqualizationHistogram EqualizationHistogram Equalization

Digital Image Processing 26

Histogram Equalization Histogram Equalization -- ExampleExampleHistogram Equalization Histogram Equalization -- ExampleExample

3

4

5

6

No. of pixels

2 3 3 2

4 2 4 3

Digital Image Processing 274x4 image

Gray scale = [0,9]histogram

0 1

1

2

2

3

3

4 5 6 7 8 9

Gray level

3 2 3 5

2 4 2 4

Histogram Equalization Histogram Equalization -- ExampleExampleHistogram Equalization Histogram Equalization -- ExampleExample

Gray Level 0 1 2 3 4 5 6 7 8 9

No.of pixels 0 0 6 5 4 1 0 0 0 0

0 0 6 11 15 16 16 16 16 16

Digital Image Processing 28

0 0 6 11 15 16 16 16 16 16

0 06 /

16

11 /

16

15 /

16

16 /

16

16/

16

16/

16

16/

16

16/

16

s x 9 0 03.3

≈3

6.1

≈6

8.4

≈89 9 9 9 9

Histogram Equalization Histogram Equalization -- ExampleExampleHistogram Equalization Histogram Equalization -- ExampleExample

4

5

6

No. of pixels

3 6 6 3

8 3 8 6

Digital Image Processing 29Output image

Gray scale = [0,9]

Histogram equalization

0 1

1

2

2

3

3

4 5 6 7 8 9Gray level

6 3 6 9

3 8 3 8

Histogram EqualizationHistogram EqualizationHistogram EqualizationHistogram Equalization

nrow=512; ncol=512; npixels = nrow*ncol;maxlevel = 255;void hist_equalize(int im[][], nrow, ncol) {

int hist[maxlevel+1], sum[maxlevel+1];// initialize : hist[]=0;

for (int k=0; k<=maxlevel; k++) hist[k]=0;// calc histogram

for (int i =0; i<nrow;i++) for (int j=0; j<ncol; j++)

hist[ im[i][j] ]++;

Digital Image Processing 30

hist[ im[i][j] ]++;// calc sum

sum[0] = hist[0];for (int k=1; k<=maxlevel; k++) sum[k]=sum[k-1]+hist[k];

// calc normalized sum : for (k=0; k<=maxlevel; k++)

sum[k] = (int) ((float) (sum[k]*maxlevel) / (float)npixels + 0.5);// transform : sum[] acts as LUT

for (int i =0; i<nrow;i++) for (int j=0; j<ncol; j++)

im[i][j] = sum[ im[i][j] ];}

Color Histogram EqualizationColor Histogram EqualizationColor Histogram EqualizationColor Histogram Equalization

Digital Image Processing 31Original Image Equalized Image

Digital Image Processing

Digital Image Processing

STOP HERE 2014/01/21

Digital Image Processing 34

Digital Image Processing 35

Histogram Specification Histogram Specification -- ApplicationApplicationHistogram Specification Histogram Specification -- ApplicationApplication

� We wish to check if a circuit board (image 1) matches the template (image 2) from which it was manufactured. Any defects?

Digital Image Processing 36

Histogram Specification Histogram Specification -- ApplicationApplicationHistogram Specification Histogram Specification -- ApplicationApplication

� Compute difference image (defined later), threshold by setting pixels with non-zero absolute difference to 1 and all other pixels to 0:

Digital Image Processing 37

Histogram Specification Histogram Specification -- ApplicationApplicationHistogram Specification Histogram Specification -- ApplicationApplication

� What if the overall brightness of image 1 is different from that of image 2?

Digital Image Processing 38

Histogram SpecificationHistogram SpecificationHistogram SpecificationHistogram Specification

Digital Image Processing 39

Steps of AlgorithmSteps of AlgorithmSteps of AlgorithmSteps of Algorithm

� Step 1:

Find histogram of input image , and find its cumulative , the histogram equalization mapping function:

� Step 2:

Specify the desired histogram , and find its

cumulative , the histogram equalization mapping

xh

xH

0

[ ] [ ]j

x x

i

H j h i=

=∑

zh

H

Digital Image Processing 40

cumulative , the histogram equalization mapping

function:

� Step 3: Relate the two mapping above to build a lookup table for the overall all mapping.

Specifically, for each input level i, find and output level j so that best matches

And then,

zH

0

[ ] [ ]j

z z

i

H j h i=

=∑

[ ]z

H j [ ]x

H i

[ ] [ ] min | [ ] [ ] |x z k x zH i H j H i H k− = −

[ ]lookup i j=

Histogram Specification Histogram Specification -- ExampleExampleHistogram Specification Histogram Specification -- ExampleExample

Digital Image Processing 41

Histogram Specification Histogram Specification -- ExampleExampleHistogram Specification Histogram Specification -- ExampleExample

� Step 1: Equalize px

Digital Image Processing 42

Histogram Specification Histogram Specification -- ExampleExampleHistogram Specification Histogram Specification -- ExampleExample

� Step 2: Equalize pz

Digital Image Processing 43

Histogram Specification Histogram Specification -- ExampleExampleHistogram Specification Histogram Specification -- ExampleExample

� Step 3: Obtain overall mapping x � y � y’ � z

Digital Image Processing 44

Digital Image Processing

Histogram Specification Histogram Specification -- ProgrammingProgrammingHistogram Specification Histogram Specification -- ProgrammingProgramming

Digital Image Processing

ContrastContrastContrastContrast

� Separation of signal (image) features from background

� Contrast describes relative brightness of a feature

( )1 11

2

: 2 2S b

C CS b

−= ⇒ −

+K

: 1S b

C C−

= ⇒ − ∞K

Digital Image Processing 47

3 3 : 0S b

C CS

−= ⇒ ∞K

2 2 : 1S b

C Cb

−= ⇒ − ∞K

30%

36%

36%

42%

C1 =0.18 C1 =0.15

Contrast ValuesContrast ValuesContrast ValuesContrast Values

Digital Image Processing 48

30% 36%

42%

48%

48%

54%

C1 =0.13 C1 =0.12

Contrast StretchingContrast StretchingContrast StretchingContrast Stretching

� Contrast stretching is applied to an image to stretch a histogram to fill the full dynamic range of the image.

� It works best with images that have a Gaussian or near-Gaussian distribution.

Digital Image Processing 49Low and high contrast histograms

Contrast StretchingContrast StretchingContrast StretchingContrast Stretching

� Basic Contrast Stretch

� Expands the image histogram to cover all ranges (0~255) of pixels.

255

new

pix

el

( )1 1y y a x x− = −

Digital Image Processing 50� Works best on images that have all pixels concentrated in one

part of the histogram, the middle.

oldpixel

low high0

( )1 1y y a x x− = −

( )2 5 5

n e w p ix e l o ld p ix e l lo wh ig h lo w

= −−

Contrast StretchingContrast StretchingContrast StretchingContrast Stretching

� End-In-Search

� A certain percentage of the pixels must be saturated to full white or full black.

0 for x low≤

255

y

Digital Image Processing 51� Works well for images that have pixels of all possible intensities

but have a pixel concentration in one part of the histogram.

( )255 for low x high

255 for high x

x lowy

high low

−= × ≤ ≤

− ≤

low high0

x

255

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Convert an old pixel into a new pixel based on some predefined function.

� Easily implemented with simple look-up tables.(ex: image negative)

255

255

Digital Image Processing 52

old pixel0

new

pix

el

255 old pixel0

new

pix

el

255

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Image Negative

Digital Image Processing

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Power-law:

Digital Image Processing 54

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Power-law:

Digital Image Processing 55

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Power-law:

Digital Image Processing 56

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Gamma CorrectionOften used in image processing to compensate for nonlinear responses in imaging sensors, displays and film.

1 /Y X

γ=

XGamma

Correction

255

255

255

255255

XY

γ

= ×

Digital Image Processing 57

old pixel0

new

pix

el

255 old pixel0

new

pix

el

255 old pixel0

new

pix

el

255

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

Digital Image Processing 58Fig. 2.16 (a) Gamma correction transformation with γ=0.45;(b) gamma corrected image; (c) gamma correction transformation with γ=2.2; (d) gamma corrected image.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Contrast Stretch/Compression Transformations

old pixel0

255

new

pix

el

255 old pixel0

255

new

pix

el

255 old pixel0

255

new

pix

el

255

Digital Image Processing 59

old pixel0 255 old pixel0 255 old pixel0 255

contrast stretchedoriginal contrast compressed

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

Digital Image Processing 60Fig. 2.17 (a) Contrast stretch transformation; (b) contrast stretched image; (c) Contrast compression transformation; (d) contrast compressed image.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

Digital Image Processing 61

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Posterize TransformationReduces the number of gray levels in an image

Digital Image Processing 62Fig. 2.18 (a) 8-Level posterize transformation;(b) posterized image; (c) threshold transformation;(d) threshold image; (e) bounded threshold;(f) bounded threshold image.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Bit-Clipping

� Sets a certain number of the most significant bits of a pixel to 0.

� Effect of breaking up an image into several subregions with the same intensity cycles.

Setting 1 MSB to zero Setting 2 MSB’s to zero

Digital Image Processing 63

000 000 0

001 001 1

010 010 2

011 011 3

100 000 0

101 001 1

110 010 2

111 011 3

Fig. 2.19 (a) 2-bit bit-clipping transformation;(b) resulting image.

63

Fig. 2.20 Bit clipped imagecontrast stretched.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Iso-Intensity Transformation

� Sets particular input intensity values to black or white.

� Can be used to create contours on an image at specific intervals.

Digital Image Processing 64Fig. 2.21 (a) Iso-intensity contouring transformation; (b) contoured image.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Range-Highlighting Transformation

Fig. 2.22 (a) Range-highlighting transformation; (b) resulting image.

Digital Image Processing 65

� Solarize Transformation

transformation; (b) resulting image.

Fig. 2.23 (a) Solarize transformation using a threshold of 150; (b) solarized image.

Intensity TransformationsIntensity TransformationsIntensity TransformationsIntensity Transformations

� Parabola Transformations

Digital Image Processing 66Fig. 2.24 (a) First parabola transformation; (b) transformed image; (c) second parabola transformation; (d) second transformed image.

top related