ece 484 digital image processing lec 04 - point operations ... · manipulating dynamic ranges of...

36
ECE 484 Digital Image Processing Lec 04 - Point Operations & Quantization Zhu Li Dept of CSEE, UMKC Office: FH560E, Email: [email protected], Ph: x 2346. http://l.web.umkc.edu/lizhu office hour: Tu/Th 2:30-4pm@FH560E Z. Li, ECE484 Digital Image Processing, 2019. p.1

Upload: others

Post on 22-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

ECE 484 Digital Image Processing Lec 04 - Point Operations & Quantization

Zhu Li

Dept of CSEE, UMKC

Office: FH560E, Email: [email protected], Ph: x 2346.

http://l.web.umkc.edu/lizhu

office hour: Tu/Th 2:30-4pm@FH560E

Z. Li, ECE484 Digital Image Processing, 2019. p.1

Page 2: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Outline

Recap of Lec 03 Point Operations Image Quantization Summary

Z. Li, ECE484 Digital Image Processing, 2019. p.2

Page 3: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Camera Projection: Intrinsic + Extrinsic Parameters Camera Intrinsic + Extrinsic Parameters:

Intrinsic: camera center:[u0, v0], focus length/aspect ratio: Extrinsic: Rotation R=RxRyRz, translation t=[tx, ty, tz]

Z. Li, ECE484 Digital Image Processing, 2019. p.3

Ow

iw

kw

jwR,t

X

x

Page 4: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Homography In general, homography H maps 2d points

according to, x’=Hx

Up to a scale, as [x, y, w]=[sx, sy, sw], so H has 8 DoF

Affine Transform: 6 DoF: Contains a translation [t1, t2], and

invertable affine matrix A[2x2]

Similarity Transform, 4DoF: a rigid transform that preserves

distance if s=1:

Z. Li, ECE484 Digital Image Processing, 2019. p.4

Page 5: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Homography Estimation – SVD Pseudo Inv

In matrix form, we have, Ah = 0 If we have more than 4, then the system is over-determined, we

will find a solution by least squares, computationally via SVD

Pseudo Inverse: SVD: Pseudo inverse (minimizing least square error)

Details: https://www.ecse.rpi.edu/~qji/CV/svd_review.pdf

Z. Li, ECE484 Digital Image Processing, 2019. p.5

Page 6: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Outline

Recap of Lec 03 Point Operations Image Quantization Summary

Z. Li, ECE484 Digital Image Processing, 2019. p.6

Page 7: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Types of Image Processing Opeartions

Geometrical Transform Rotation, translation Affine transform I(x,y) -> J(x, y): pixel values not

changed but moving around

Spatial Processing Directly operating on the pixel values

within the image Neighborhood based (3x3) Point operation: 1x1

Transform Domain Processing J(u,v) = T(I(x,y)), DCT, FFT, e.g.

Z. Li, ECE484 Digital Image Processing, 2019. p.7

Page 8: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Spatial Domain Processing

: Spatial operator defined on a neighborhood N of a given pixel

point processing mask/kernel processing

Application

Method

-8-Z. Li, ECE484 Digital Image Processing, 2019.

Page 9: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Intensity transformation / point operation Map a given gray or color level u to a

new level v

Memory-less, direction-less operation output at (x, y) only depend on the input

intensity at the same point Pixels of the same intensity gets the same

transformation Does not bring in new information,

may cause loss of information But can improve visual appearance or

make features easier to detect

input gray level u

outp

ut g

ray

leve

l

v

-9-Z. Li, ECE484 Digital Image Processing, 2019.

Page 10: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Simple Image Statistics

Pixel mean and variance im=imread('lenna.png'); m = mean(double(im(:))); v = var(double(im(:)));

Pixel histogram (pmf) [pixel_count, value]= hist(double(im(:)), [0 255]);

Z. Li, ECE484 Digital Image Processing, 2019. p.10

Page 11: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Binarization by pixel value thresholding %binarize mx = mean(double(im(:))); vx = var(double(im(:))); im2 = zeros(512,512); im2(find(im>mx))=255; imagesc(im2);

Z. Li, ECE484 Digital Image Processing, 2019. p.11

Page 12: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Point Operation - Histogram, Binarization, Negative

Z. Li, ECE484 Digital Image Processing, 2019.

Matlab % histogram figure(32); colormap('gray');im1=imread('data/lenna.png'); im = rgb2gray(im1); subplot(2,2,1); imagesc(im); title('lenna');[h, v]=hist(double(im(:)), [0:255]); subplot(2,2,2); bar(v, h); grid on; title('hist');

%binarizemx = mean(double(im(:))); vx = var(double(im(:)));im2 = zeros(512,512); im2(find(im>mx))=255;

% digital negativeim3 = 255*ones(512, 512) - double(im);

subplot(2,2,3); imagesc(im2); title('binarize'); subplot(2,2,4); imagesc(im3); title('negative');

p.12

Page 13: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

image negatives

the appearance of photographic negatives

Enhance white or gray detail on dark regions, esp. when black areas are dominant in size

-13-Z. Li, ECE484 Digital Image Processing, 2019.

Page 14: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Basic intensity transform functions

monotonic, reversible compress or stretch certain range of gray-levels

-14-Z. Li, ECE484 Digital Image Processing, 2019.

Page 15: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Freq Domain Log Mapping

Freq domain operations

Z. Li, ECE484 Digital Image Processing, 2019. p.15

lena

FFT(lena) stretch:u 2 [0, .5] v 2 [0, .59]

compress:u 2 [.5, 1] v 2 [.59, 1]im = imread(‘lena.png’)

a = abs(fftshift(fft2(double(im))));c = log(1+double(im)); c = range_normalize(c);b = log(1+a); b=b/max(b(:));

Page 16: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Gamma Correction

Matching Display characteristics

Z. Li, ECE484 Digital Image Processing, 2019. p.16

power-law response functions in practiceCRT Intensity-to-voltage

function has ¼ 1.8~2.5Camera capturing distortion

with c = 1.0-1.7 Similar device curves in

scanners, printers, …

power-law transformations are also useful for general purpose contrast manipulation

Page 17: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Gamma Correction

Make image characteristis match display (voltage-brightness )

Z. Li, ECE484 Digital Image Processing, 2019. p.17

make linear input appear linear on displays method: calibration pattern + interactive adjustment

Page 18: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Effects of Gamma Correction

On images...

Z. Li, ECE484 Digital Image Processing, 2019. p.18

L02.2 L0

1/2.2L0

Page 19: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Histogram Equalization

Why histogram equalization ?

Z. Li, ECE484 Digital Image Processing, 2019. p.19

if pixel values are i.i.d random variables histogram is an estimate of the probability distribution of the r.v.

“unbalanced” histograms do not fully utilize the dynamic range Low contrast image: narrow

luminance range Under-exposed image:

concentrating on the dark side Over-exposed image:

concentrating on the bright side

“balanced” histogram gives more pleasant look and reveals rich details

Page 20: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Contrast Stretching

Map intensity to a larger range

Z. Li, ECE484 Digital Image Processing, 2019. p.20

0 L-1

L-1

Stretch the over-concentrated gray-levelsPiece-wise linear function, where the slope in the stretching region is greater than 1.

Page 21: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Objectives of Histogram Equalization Objectives

Z. Li, ECE484 Digital Image Processing, 2019. p.21

goal: map the each luminance level to a new value such that the output image has approximately uniform distribution of gray levels

two desired properties monotonic (non-decreasing) function: no value reversals [0,1][0.1] : the output range being the same as the input range

pdf

cdf

o

1

1o

1

1

Page 22: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Histogram Equalization

Algorithm

Matlab

Z. Li, ECE484 Digital Image Processing, 2019. p.22

make

show

o

1

1

im = imread(‘lena.png’)[im1,T]=histeq(rbg2gray(im));plot((0:255)/255,T);

T: cdf of lena

Page 23: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Equalization Algorithm

Alogrithm Sketch

Z. Li, ECE484 Digital Image Processing, 2019. p.23

Rounding or Uniform

quantization

u v v’

pu(xi)

compute histogram

equalize

round the output

or

Only depend on the input image histogram

Fast to implement For u in discrete prob.

distribution, the output v will be approximately uniform

Page 24: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Outline

Recap of Lec 03 Point Operations Image Quantization Summary

Z. Li, ECE484 Digital Image Processing, 2019. p.24

Page 25: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Image Quantization

Image quantization transfer function 

Z. Li, ECE484 Digital Image Processing, 2019. p.25

Page 26: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Uniform Quantizer The uniform quantizer’s design:

• Denote the input brightness range: • Let B – the number of bits of the quantizer => L=2B reconstruction levels• The expressions of the decision levels:

•quantization step size: q

E.g. B=2 => L=4

Z. Li, ECE484 Digital Image Processing, 2019. p.26

Page 27: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Uniform quantization error

Reconstruction

Reconstruction error in Mean Squred Error (MSE)

If P(x) is uniform: proof: homework

Z. Li, ECE484 Digital Image Processing, 2019. p.27

Page 28: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Uniform quantization and errors

Cameraman example B=1 => L=2

Non-quantized image Quantized image

Quantization error; MSE=36.2

The histogram

Z. Li, ECE484 Digital Image Processing, 2019. p.28

Page 29: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Uniform Quantization Example Finer quantization B=2 => L=4

Non-quantized image Quantized image

Quantization error; MSE=15

histogram

Z. Li, ECE484 Digital Image Processing, 2019. p.29

Page 30: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Quantization: B=3, L=8

Finer quantization: B=3 => L=8; false contours present

Non-quantized image Quantized image

Quantization error; MSE=7.33

histogram

Z. Li, ECE484 Digital Image Processing, 2019. p.30

Page 31: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Distribution Optimal Quantization

Lloyd-Max Quantization, optimize w.r.t to tk, rk

we have

which means, tk is the mid point between two reconstructions, while rk is the average.

Z. Li, ECE484 Digital Image Processing, 2019. p.31

Page 32: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

LMQ error

The MSE from LMQ: assuming piece-wise linear PDF of X

The MSE is estimated as,

Z. Li, ECE484 Digital Image Processing, 2019. p.32

Page 33: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Lloyd-Max Quantization Example

LMQ example: B=1 => L=2Non-quantized image

Quantized image

The quantization error; MSE=19.5

The evolution of MSE in the optimization, startingfrom the uniform quantizer

Z. Li, ECE484 Digital Image Processing, 2019. p.33

Page 34: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

LMQ example

LMQ: B=2, L=4

The quantization error; MSE=9.6

Non-quantized image Quantized image

The evolution of MSE in the optimization, startingfrom the uniform quantizer

Z. Li, ECE484 Digital Image Processing, 2019. p.34

Page 35: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

LMQ

LMQ: B=3, L=8

The quantization error; MSE=5

Non-quantized image Quantized image

The evolution of MSE in the optimization, startingfrom the uniform quantizer

Z. Li, ECE484 Digital Image Processing, 2019. p.35

Page 36: ECE 484 Digital Image Processing Lec 04 - Point Operations ... · manipulating dynamic ranges of images, give it more resolution, improves its quality Gamma correction (display adaptation)

Summary

Point operations Operates on the imput intensity value, has no memory of the

neigbhouring pixels manipulating dynamic ranges of images, give it more resolution,

improves its quality Gamma correction (display adaptation) Histogram equalization Quantization - uniform: most widely used these days Lloyd-Max quantiztion: adaptive to distribution

Z. Li, ECE484 Digital Image Processing, 2019. p.36