sccs 4761 point processing basic image processing operations arithmetic operations histograms

38
SCCS 476 1 Point Processing • Basic Image Processing Operations • Arithmetic Operations • Histograms

Upload: cameron-benson

Post on 17-Dec-2015

240 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 1

Point Processing• Basic Image Processing Operations

• Arithmetic Operations

• Histograms

Page 2: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 2

Basic Image Processing Operations

• Transforms

– process entire image as one large block

• Neighborhood processing

– process the pixel in a small neighborhood of pixels around the given pixel.

• Point operations

– process according to the pixel’s value alone (single pixel).

Image-Processing operations may be divided into 3 classes based on information required to perform the transformation.

Page 3: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 3

Schema of Image Processing

ImageTransformed

Image

Transform

OutputImage

Inverse TransformProcessed

Transformed Image

Image-processing operation

Page 4: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 4

Arithmetic Operations

• Addition

• Subtraction

• Multiplication

• Division

• Complement

Page 5: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 5

Arithmetic Operations (cont)

• Addition: y = x + c

• Subtraction: y = x - c

• Multiplication: y = cx

• Division: y = x/c

• Complement: y= 255 - x

Let x is the old gray value, y is the new gray value, c is a positive constant.

Page 6: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 6

Arithmetic Operations (cont)• Addition: y = x + c

• Subtraction: y = x - c

• Multiplication: y = cx

• Division: y = x/c

• Complement: y= 255 - x

To ensure that the results are integers in the range [0, 255], the following operations should be performed

• Rounding the result to obtain an integer• Clipping the result by setting

• y = 255 if y > 255• y = 0 if y < 0

Page 7: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 7

Arithmetic Operations (cont)

• MATLAB functions– Addition: imadd(x,y)

• Add two images or add constant to image

– Subtraction: imsubstract(x,y)• Subtract two images or subtract constant to image

– Multiplication: immultiply(x,y)• Multiply two images or multiply image by constant

– Division: imdivide(x,y)• Divide two images or divide image by constant

– Complement: imcomplement(x)

Page 8: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 8

Addition & Subtraction• Lighten/darken the image• Some details may be lost• MATLAB:

– commands: • x = imread(‘filename.ext’);• y = uint8(double(x) + c); or• y = uint8(double(x) - c);

– function: • x = imread(‘filename.ext’);• y = imadd(x, c); or• y = imsubtract(x, c);

Page 9: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 9

Ex: Addition & Subtraction

Added by 128

Subtracted by 128

Draw graphs of the transformation functions !!!

Page 10: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 10

Multiplication & Division

• Lighten/darken the image

• Some details may be lost (but less than addition/subtraction)

• MATLAB:

– commands: • x = imread(‘filename.ext’);• y = uint8(double(x)*c); or• y = uint8(double(x)/c);

– functions: • x = imread(‘filename.ext’);• y = immultiply(x, c); or• y = imdivide(x, c);

Page 11: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 11

Ex: Multiplication & Division

Multiplied by 2

Divided by 2

Draw graphs of the transformation functions !!!

Page 12: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 12

Comparison: Addition VS Multiplication

Page 13: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 13

Comparison: Subtraction VS Division

Page 14: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 14

Complement

• Create the negative image

• MATLAB:– commands:

• x = imread(‘filename.ext’);• y = uint8(255 - double(x));

– function: • x = imread(‘filename.ext’);• y = imcomplement(x);

Page 15: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 15

Ex: Complement

Draw a graph of the transformation function !!!

Page 16: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 16

Histogram

• Graph showing the number of pixels for each intensity

• Normalized histogram: histogram where the number of pixel is divided by the total number of pixel so the range is [0,1]

• Cumulative histogram: histogram which shows the number of pixels whose intensity is less or equal to each intensity.

Page 17: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 17

Histogram Example

>> p = imread(‘pout.tif’)>> inshow(p)

>> figure;imhist(p)

Page 18: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 18

What Histogram Describes?• Brightness

– dark image has gray levels (histogram) clutered at the lower end.

– bright image has gray levels (histogram) clutered at the higher end.

• Contrast– well contrasted image has gray levels (histogram)

spread out over much of the range.– low contrasted image has gray levels (histogram)

clutered in the center.

Page 19: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 19

Contrast Enhancement by Spreading Out Histogram

• Histogram Stretching

(Contrast Stretching)

• Histogram Equalization

Page 20: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 20

1. Histogram Stretching

0 maxI I

#pixel #pixel

Imin Imax

Page 21: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 21

Steps of Histogram/Contrast Stretching• Create the histogram of the image

Gray level ( i ) No. of gray value ( ni )

0…………………………………………….15

1…………………………………………….. 0 2…………………………………………….. 0 3……………………………………………. .0 4…………………………………………….. 0 5…………………………………………….70 6……………………………………………110 7…………………………………………….45 8…………………………………………… 70 9…………………………………………….35 10………………………………………..... . 0 11………………………………………….. 0 12…………………………………………... 0 13…………………………………………… 0 14…………………………………………… 0 15………………………………………….. 15

Draw the histogram.

Page 22: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 22

Steps of Histogram/Contrast Stretching (cont)

• From the histogram, stretch out the gray levels in the center of the range by applying the piecewise linear function – Ex: [5,9] [2,14]– y = [(14 – 2)/(9 – 5)](x – 5) + 2, Draw a graph of transformation

• Gray levels outside this range are either left as original values or transforming according to the linear function at the ends of the graph.

x y5 26 57 88 119 14

Page 23: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 23

Steps of Histogram/Contrast Stretching (cont)

• Change the old gray values to the new gray values by using the piecewise linear function from the previous step as a mapping function.

• Create the histogram from the new image

Page 24: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 24

Histogram Stretching: Example

original output

Page 25: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 25

Histogram before/after Adjustment

Before After

Page 26: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 26

Histogram Mapping: Piecewise Linear

I

#pixel

Imin Imax I

#pixel

Imin Imax

Mapping function:

21;1)12()12(

)1(2or 1 ;

IxIIxIyIyIyIxIx

IxIIxIIxII

Ix1 Ix2 Iy1 Iy2

Page 27: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 27

MATLAB: Histogram/Contrast Stretching

• Command: imadjust

• Syntax: imadjust(x, [a,b], [c,d]);

imadjust(x, [a,b], [c,d], );– convert intensity x a to c

– convert intensity x b to d

– values of a,b,c,d must be between 0 and 1 : positive constant (describe the shape of the function,

< 1 concave downward, > 1 concave upward)

Page 28: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 28

Transformation Function with Gamma (Power –Law Transformation)

Brighten image Linear mapping Darken image

ccdab

ainputoutput

)(

Page 29: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 29

Example of Adjusting by the Power-Law Transformation

Original Adjust by usingGamma = 0.5

Page 30: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 30

MATLAB: Piecewise Linear

• A MATLAB function for applying a piecewise linear-stretching function (see Figure 4.15)

• Command: find• Syntax: find(condition)• Ex

pix = find(im >= a(i) & im < a(i+1));

pix holds the index for members in im having intensity between a(i) and a(i+1) include a(i).

Page 31: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 31

2. Histogram Equalization

• The trouble with the methods of histogram stretching is that they require user input.

• Histogram equalization is an entirely automatic procedure.

• Idea: Each gray level in the image occurs with the same frequency.

• Give the output image with uniform intensity distribution.

Page 32: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 32

Histogram Equalization (cont)

• Mapping function:

where p(i) is the PDF of the intensity level i,

obtained from cumulative histogram.

,)()(0

inputf

iinputoutput ipfg

Page 33: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 33

Histogram Equalization: Procedure

Example: Suppose a 4-bit grayscale image has the histogram associated with a table of the numbers ni of gray values. (page 78)

Page 34: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 34

Histogram Equalization: Example

BEFORE AFTER

http://www.mathworks.com/access/helpdesk/help/toolbox/images/histeq.html

Page 35: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 35

MATLAB: Histogram Equalization

• Command: histeq• Syntax: histeq(image, target_hist) histeq(image, #bin)

histeq(indexed_im, #bin, target_hist) histeq(indexed_im, map, #bin)

• Default: #bin = 64• Output: output_im, [output_im, transform],

new_map, [new_map, transform]

Page 36: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 36

Lookup Tables

• Improve the performance of point processing

• Why?– one intensity is always mapped to the same value– reduce the computing time

• Lookup table: array

Input intensity: index in the array

Output intensity: value of the member

Page 37: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 37

Ex: Lookup Table (1)

• Function: output = input/2;

• MATLAB

>> T = uint8(floor(0:255)/2);

>> output = T(input);

Page 38: SCCS 4761 Point Processing Basic Image Processing Operations Arithmetic Operations Histograms

SCCS 476 38

Ex: Lookup Table in MATLAB (2)

• Function:

• MATLAB>> T1 = 0.6667*[0:95];>> T2 = 2*[96:160] – 128;

>> T3 = 0.6632*[161:255] + 85.8947;>> T = uint8(floor([T1 T2 T3]));

inputinput

inputinput

inputinput

output

161;8947.856632.0

16196 ;1282

96 ;6667.0