0% found this document useful (0 votes)
40 views49 pages

Chapter2.4 Point Operations

Here are the steps: 1) Identify the range to stretch: [A, B] = [5, 9] 2) Choose the new range: [Anew, Bnew] = [0, 255] 3) Apply the transfer function: gnew = ((Bnew - Anew)/(B - A)) * (g - A) + Anew For g = 5, gnew = 0 For g = 9, gnew = 255 For other g, interpolate linearly 4) The stretched histogram and enhanced image. This stretches the histogram and increases contrast.

Uploaded by

David Zhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views49 pages

Chapter2.4 Point Operations

Here are the steps: 1) Identify the range to stretch: [A, B] = [5, 9] 2) Choose the new range: [Anew, Bnew] = [0, 255] 3) Apply the transfer function: gnew = ((Bnew - Anew)/(B - A)) * (g - A) + Anew For g = 5, gnew = 0 For g = 9, gnew = 255 For other g, interpolate linearly 4) The stretched histogram and enhanced image. This stretches the histogram and increases contrast.

Uploaded by

David Zhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Point Operations

• ARITHMETIC OPERATIONS
• HISTOGRAM PROCESSING

COMP411 1
Image Processing Methods in Spatial Domain
Spatial domain refers to the image plane itself.
Image processing methods in spatial domain may be divided into 2
principle categories
1. Point operations/Intensity transformation
◦ operate on single pixels of an image
◦ principally for the purpose of contrast manipulation and image thresholding
2. Spatial filtering
◦ process the pixel in a small neighborhood of pixels around the given pixel
◦ deals with performing operations, such as image sharpening

COMP411 2
Image Processing Methods in Spatial Domain
The spatial domain processes can be denoted by the expression,

g ( x, y ) = T  f ( x, y ) 

Where f(x,y) is the input image, g(x,y) is the output image and T is the
operator on f defined over the point (x,y) or a neighbourhood of the
point (x,y).
0 x R

3x3 neighborhood
y of (x,y)

Image f Spatial Domain


C

COMP411 3
Arithmetic Operations
Let r is the old grey level value of a pixel, s is the new grey
level value of a pixel, c is a positive constant.
Addition: s=r+c s=r+c
s s=r
s=r-c

c
Subtraction: s=r–c
0 c r

COMP411 4
Arithmetic Operations
Let r is the old grey level value of a pixel, s is the new grey
level value of a pixel, c is a positive constant.
s=2r
s s=r
Multiplication: s = cr

c
s=r/2
Division: s = r/c
0 c r
s s=r
Complement: s= 255 - r

c
s=255-r
0 c r
COMP411 5
Arithmetic Operations (cont)
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
and
• Clipping the result by
• setting s = 255, if s > 255
• setting s = 0, if s < 0
or
• Wrap-around the results by
• set s = s-255*n, if s > 255
• set s = 0, if s < 0

COMP411 6
Example
grey level:7-76

COMP411 7
x3
grey level:21-228

COMP411 8
x5:clipping

Old pixel value > 51 ➔ new pixel value > 255


Those pixel values are clipped to be 255.

COMP411 9
It is often safest to change to an image

x5:Wrap around format with a large range, e.g. floating


point, before multiplication.

Old pixel value > 51 ➔ new pixel value > 255


Those pixel values are wrapped around from 255 back
to 0.
COMP411 10
Addition & Subtraction
•Lighten/darken the input image
•Some details may be lost and those are not retrievable.
(because of the rounding and clipping)

•MATLAB code

commands:
r = imread(‘filename.ext’);
s1 = uint8(double(r) + c);
s2 = uint8(double(r) - c);

COMP411 11
Example: Addition & Subtraction

Added by 128

Subtracted by 128
Some
details are
lost!

COMP411 12
Multiplication & Division
•Lighten/darken the image
•Some details may be lost and those are not retrievable.
(but less than addition/subtraction)
•MATLAB code

r = imread(‘filename.ext’);
s1 = uint8(double(r)*c); or
s2 = uint8(double(r)/c);

COMP411 13
Example: Multiplication & Division

Multiplied by 2

Divided by 2
Some
details are
lost!

COMP411 14
Comparison: Addition VS Multiplication

Addition Multiplication

COMP411 15
Comparison: Subtraction VS Division

Subtraction Division

COMP411 16
Complement
•Create the negative image.
•Suited for enhancing white or grey details embedded in
dark regions of an image, especially when the black areas
are dominant in size.
•MATLAB Code:

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

COMP411 17
Example: Complement

COMP411 18
Example: Complement
Mammogram using negative transformation

Easy to see
tissues in
negative image

COMP411 19
Recap: Histogram
•Histogram:
◦ A graph showing the number of pixels at each intensity level or color.

•Normalized histogram:
◦ A histogram where the number of pixel is divided by the total
number of pixels, so the range is [0,1]
◦ corresponding to the pdf function.

•Cumulative histogram:
◦ A histogram which shows the number of pixels whose intensity is less
or equal to each intensity divided by the total number of pixels.
◦ corresponding to the CDF function.

COMP411 20
Recap: Histogram

>> p = imread(‘pout.tif’)
>> figure; histogram(p)
>> imshow(p)

COMP411 21
What does Histogram describe?
Brightness
◦ Dark image has grey levels (histogram) cluttered at the lower end.
◦ Bright image has grey levels (histogram) cluttered at the higher end.

Contrast
◦ Well-contrasted image has grey levels (histogram) spread out over much of
the range.
◦ Low-contrasted image has grey levels (histogram) cluttered in the center.

COMP411 22
Contrast Enhancement
Contrast enhancement by spreading out Histogram
1. Histogram Stretching/Contrast Stretching

2. Histogram Equalization

COMP411 23
Histogram/Contrast Stretching
•A process that expanding the range of the intensity levels
in an image so that it expands the full intensity range of the
recording medium or display device.

#pixel #pixel

Intensity Intensity
A B level Anew Bnew level

COMP411 24
Histogram/Contrast Stretching
Stretch out the grey levels in the center of the range by
applying the piecewise linear function:

 A, B  →  Anew , Bnew  gnew

 Bnew − Anew  Bnew


  ( g − A) + Anew A  g  B
g new =  B − A 
g g  A or g  B
 Anew

Where g is the old grey level, 0 A B g


gnew is the stretched grey level, Transfer function
Anew can be 0 and Bnew can be 255.

COMP411 25
Example: Histogram/Contrast Stretching
Given an image with histogram shown as below:

grey level-g # of pixels has g-HI(g)


0 15
1 0
2 0
3 0 #pixels
4 0 110
5 70
6 110
7 45
8 70
9 35
10 0
11 0
12 0
13 0 0 5678 9 15 g
14 0
15 15

COMP411 26
Example: Histogram/Contrast Stretching
 A, B  →  Anew , Bnew 

 Bnew − Anew 
 ( g − A) + Anew A  g  B
g new =  B − A 
g g  A or g  B

#pixel #pixel

g gnew
A B Anew Bnew

COMP411 27
Example: Histogram/Contrast Stretching
•Stretch grey levels from [5, 9] to [2, 14]
Old grey level New grey level
g gnew
 14 − 2 
=  ( g − 5) + 2 5 g 9 5 2
g new
 9−5  6 5
7 8
8 11
9 14

•grey levels outside this range are left as original values.

g new = g g  5 or g  9

COMP411 28
Example: Histogram/Contrast Stretching
New grey level- # of pixels has g-HI(gnew)
gnew
0 15
1 0
2 70
3 0
4 0
5 110
6 0
7 0
8 45
9 0
10 0
11 70
12 0
13 0
14 35
15 15

The histogram after stretching

COMP411 29
Example: Histogram/Contrast Stretching

original output

COMP411 30
Example: Histogram/Contrast Stretching

[66,238] [0,255]

COMP411 31
Matlab/Scilab: Histogram/Contrast Stretching
From image processing toolbox
Command: imadjust
Syntax:
J=imadjust(I,[A,B],[C,D],gamma);

◦ convert intensity I  A to B
◦ convert intensity I  C to D
◦ values of A,B,C and D must be between 0 and 1
◦ Gamma (𝛾): specifies the shape of the curve describing
the relationship between the values in I and J. (positive
constant; < 1 concave downward, > 1 concave upward)

COMP411 32
Gamma value (Power–Law Transformation)


 input − a 
output =   (d − c) + c
 b−a 

Brighten image Linear mapping Darken image

COMP411 33
Gamma value (Power–Law Transformation)

Original Adjust by using


Gamma = 0.5

COMP411 34
Matlab/Scilab: Piecewise Linear
A function for applying a piecewise linear-stretching
function
Command: find
Syntax: find(condition)
Example:
pix = find(I >= A & I < B);

pix holds the index for members in I having intensity


between A and B include A.
Similar syntax:
pix = I >= A & I < B;

COMP411 35
Histogram Equalization
•The trouble with the methods of histogram/contrast
stretching is that they require user input.
•Histogram equalization is an entirely automatic procedure.
•Idea: Each grey level in the image occurs with the same
frequency (the same number of pixel counts).
•To give the output image with uniform intensity
distribution.
•To maximize the contrast evenly across the entire image.

COMP411 36
Histogram Equalization
•Intensity level gnew of the output image Inew
g
g new = T ( g ) =  pI ( ),
 =0

where g is the intensity level of input image I. pI(α) is the probability


g
density function (pdf) for intensity level α .  pI ( ) is the cumulative
 =0
distribution function (CDF) of intensity level g. The normalized
gnew (the range
of gnew is 0-1)
•The pdf of output image Inew is uniform.
1 for 0  g new  1
pΙnew ( g new ) = 
0 otherwise
COMP411 37
Example: Histogram Equalization
Suppose that a 3-bit grayscale image of size 64x64 pixels has the
intensity distribution as below:

Intensity level g Number of pixels having g


0 790
1 1023
2 850
3 656
4 329
5 245
6 122
7 81

COMP411 38
Example: Histogram Equalization

pI(g)
0.25
0.20
0.15
0.10
0.05

0 1 2 3 4 5 6 7g
pdf before histogram equalization

COMP411 39
Example: Histogram Equalization
The image has 23=8 levels from g=0-7 and the total number of pixels is
64x64=4096.
1. work out pI(g)
Intensity level g Number of pixels pI(g) =N(g)/4096
having g-h(g)
0 790 0.19
1 1023 0.25
2 850 0.21
3 656 0.16
4 329 0.08
5 245 0.06
6 122 0.03
7 81 0.02

COMP411 40
Example: Histogram Equalization
2. use pI(g) to work out gnew.
𝒈
Intens Number of 𝑝I (𝑔ሻ=h(g)
ity pixels having /4096 𝒈𝒏𝒆𝒘 = ෍𝒑I (𝒈ሻ
𝒊=𝟎
level g g-h(g)
0 790 0.19 0.19
1 1023 0.25 0.19+0.25=0.44
2 850 0.21 0.19+0.25+0.21
=0.65
3 656 0.16 0.81
4 329 0.08 0.89
5 245 0.06 0.95
6 122 0.03 0.98
7 81 0.02 1

COMP411 41
Example: Histogram Equalization
3. convert the normalized gnew to gnew with range 0-7.
4. round gnew to nearest integer.
Intens Number of 𝑝I (𝑔ሻ=h(g) 𝒈𝒏𝒆𝒘 = ෍𝒑I (𝒈ሻ
gnew with Rounded
ity pixels having /4096 𝒈
range 0-7 gnew
level g g-h(g)
0 790 0.19 0.19 1.33 1
1 1023 0.25 0.44 3.08 3
2 850 0.21 0.65 4.55 5
3 656 0.16 0.81 5.67 6
4 329 0.08 0.89 6.23 6
5 245 0.06 0.95 6.65 7
6 122 0.03 0.98 6.86 7
7 81 0.02 1 7 7

COMP411 42
Example: Histogram Equalization
3. generate the new histogram.

gnew pInew(gnew)
pInew(gnew)
1 0.19
3 0.25
0.25
5 0.21 0.20
6 0.16 0.15
6 0.08 0.10

7 0.06 0.05

7 0.03
0 1 2 3 4 5 6 7 gnew
7 0.02
pdf after histogram equalization

COMP411 43
Example: Histogram Equalization

pInew(gnew)
pI(g)
0.25 0.25
0.20 0.20
0.15 0.15
0.10 0.10
0.05 0.05

0 1 2 3 4 5 6 7g 0 1 2 3 4 5 6 7 gnew

pdf of input image I pdf of output image Inew

COMP411 44
Example: Histogram Equalization

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

COMP411 45
Matlab: Histogram Equalization
Command: histeq (from SIVP toolbox)
Syntax: histeq(image, out_graylev)
histeq(indexed_im, map, out_greylev)

Before After

COMP411 46
Lookup Tables
•Used to improve the performance of point operations
•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 number

COMP411 47
Example: Lookup Table (1)
Function: output = input/2;
MATLAB

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

COMP411 48
Ex: Lookup Table in MATLAB (2)
Function:
 0.6667  input; input  96

output =  2  input − 128; 96  input  161
0.6632  input + 85.8947;161  input

MATLAB

>> T1 = 0.6667*[0:95];
>> T2 = 2*[96:160] – 128;
>> T3 = 0.6632*[161:255] + 85.8947;
>> T = uint8(floor([T1 T2 T3]));

COMP411 49

You might also like