eece/cs 4353 image processing - internet archive
TRANSCRIPT
![Page 1: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/1.jpg)
EECE/CS 4353 Image Processing
Richard Alan Peters IIDepartment of Electrical and Computer Engineering
Fall Semester 2021
Lecture Notes:
This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ orsend a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Lecture Notes: Basic Point Processing of Images
![Page 2: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/2.jpg)
Point Processing of Images
In a digital image, a point = a pixel. Point processing transforms a pixel’s
value as function of its value alone. It does not depend on the values of
the pixel’s neighbors.
6 September 2021 1999-2021 by Richard Alan Peters II 2
![Page 3: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/3.jpg)
Examples include: Brightness and contrast adjustment Gamma correction Histogram equalization Histogram matching Color correction.
Point Processing of Images
6 September 2021 1999-2021 by Richard Alan Peters II 3
![Page 4: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/4.jpg)
Point Processing
original + gamma- gamma + brightness- brightness
original + contrast- contrast histogram EQhistogram mod
6 September 2021 1999-2021 by Richard Alan Peters II 4
Wallace and Gromit are characters created and owned byAardman Animation. Seehttps://www.aardman.com/work/#filter=.wallace-gromit
![Page 5: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/5.jpg)
Point Processing: Pixel Values
6 September 2021 1999-2021 by Richard Alan Peters II 5
A point process transforms one intensity level (or color) intoanother as a function of that one alone. So a point process is
out in .fp p
out in, , .r c f r cp p
That is, the pixel value output is dependent on only the pixel valueinput. That implies
In words, the output at one location is dependent only the value ofthe input image at that same location. Other locations don’t matter.
![Page 6: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/6.jpg)
If , ,andthen , , .
r c b gf g k
r c b k
I
J
Point Ops via Functional Mappings
Input Output
I , pointoperator JImage:
I(r,c) function, f J(r,c)Pixel:
J I
The transformation of image I into image J isaccomplished by replacing each input intensity, g, witha specific output intensity, k, at every location (r,c,b)where I(r,c,b) = g.
The rule that associates k with g is usuallyspecified with a function, f, so that f (g) = k.
6 September 2021 1999-2021 by Richard Alan Peters II 6
![Page 7: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/7.jpg)
Point Ops via Functional Mappings
6 September 2021 1999-2021 by Richard Alan Peters II 7
One-band Image
Three-band Image
J(r,c) = f ( I(r,c) ),for all pixel locations, (r,c).
J(r,c,b) = f ( I(r,c,b) ), orJ(r,c,b) = fb ( I(r,c,b) ), orfor b = 1, 2, 3, and all (r,c).
![Page 8: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/8.jpg)
J(r,c) = f ( I(r,c) ),for all pixel locations, (r,c).
J(r,c,b) = f ( I(r,c,b) ), orJ(r,c,b) = fb ( I(r,c,b) ), orfor b = 1, 2, 3, and all (r,c).
One-band Image
Three-band Image
Point Ops via Functional Mappings
Either all 3 bandsare mapped throughthe same function,f, or …
… each band ismapped througha separate func-tion, fb.
6 September 2021 1999-2021 by Richard Alan Peters II 8
![Page 9: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/9.jpg)
Look-Up Tables
6 September 2021 1999-2021 by Richard Alan Peters II 9
![Page 10: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/10.jpg)
Lookup Tables
6 September 2021 1999-2021 by Richard Alan Peters II 10
A lookup table1 is an indexed list of numbers – a vector – that canbe used to implement a discrete function – a mapping from a setof integers, {gin,1, gin,2, ... , gin,n}, to a set of numbers (integers ornot), {gout,1, gout,2, ... , gout,n}. A lookup table can implement afunction such as:
out in in out out, 1
in, out,
if , where 0, , 1 and
then define LUT 1 LUT , for 1, n .
nk k
k k
g f g g n g g
g k g k
We’ve already seen one of these, the colormap.2
1 https://en.wikipedia.org/wiki/Lookup_table ; 2 Lecture 2b, slides 15-34.In MATLAB the indexis the input value + 1.
![Page 11: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/11.jpg)
J = LUT(I+1)
Point Operations using Lookup Tables
A lookup table (LUT)can implement afunctional mapping.
,255,,0
,
g
gfkforIf
invaluesontakesifand
,255,,0k
… then the LUTthat implements fis a 256x1 arraywhose (g +1)th
value is k = f (g).
To remap animage, I, to J :
6 September 2021 1999-2021 by Richard Alan Peters II 11
LUT is 256x1.But I may beRxC or RxCx3.
In MATLAB the indexis the input value + 1.
![Page 12: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/12.jpg)
Point Operations = Lookup Table Ops
0 127 255
012
725
5
input value
outp
ut v
alue
index value...
101102103104105106...
...646869707071...
E.g.:
input output
6 September 2021 1999-2021 by Richard Alan Peters II 12
In MATLAB the indexis the input value + 1.
![Page 13: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/13.jpg)
How to Generate a Lookup Table
32/)127(1255;
255,,0.2
xaeax
xa
LetLet
For example, a sigmoid:
a = 2;x = 0:255;LUT = 255 ./ (1+exp(-a*(x-127)/32));
Or in Matlab:
This is justone example.
6 September 2021 1999-2021 by Richard Alan Peters II 13
In MATLAB, LUT isindexed from 1:256.
![Page 14: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/14.jpg)
If I is 3-band, thena) each band is mapped separately using the
same LUT for each band orb) each band is mapped using different LUTs –
one for each band.
Point Ops on RGB Images using Lookup Tables
6 September 2021 1999-2021 by Richard Alan Peters II 14
a) J = LUT(I+1),
b) J(:,:,b) = LUTb(I(:,:,b) +1), for b = 1, 2, 3.
![Page 15: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/15.jpg)
cell
inde
x
cont
ents
0 0
64 32
128 128
192 224
255 255
...
...
...
...
...
...
...
...
1-Band Lookup Table for 3-Band Image
input output
a pixel withthis value
is mapped tothis value
6 September 2021 1999-2021 by Richard Alan Peters II 15
In MATLAB thevalue is index - 1
Photo by Alan Peters,Kyoto, Japan, 1993
![Page 16: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/16.jpg)
R
G
B
Example 3-Band Image
6 September 2021 1999-2021 by Richard Alan Peters II 16
Lightning at Ramasse, Rhone-Alpes, France by Flickr user, Regarde là-bas,https://www.flickr.com/photos/marcel_s_s/8624344496/in/pool-tbasab/
R, G, B Bands
![Page 17: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/17.jpg)
R
G
B
6 September 2021 1999-2021 by Richard Alan Peters II 17
Lightning at Ramasse, Rhone-Alpes, France by Flickr user, Regarde là-bas,https://www.flickr.com/photos/marcel_s_s/8624344496/in/pool-tbasab/
with 3-Band LUT.
![Page 18: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/18.jpg)
R
G
B
6 September 2021 1999-2021 by Richard Alan Peters II 18
Lightning at Ramasse, Rhone-Alpes, France by Flickr user, Regarde là-bas,https://www.flickr.com/photos/marcel_s_s/8624344496/in/pool-tbasab/
with 3-Band LUT. R is mappedthrough asigmoid.
G is mapped toits negative
The dark values of B are contraststretched while the light valuesare negated and stretched.
![Page 19: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/19.jpg)
6 September 2021 1999-2021 by Richard Alan Peters II 19
Lightning at Ramasse, Rhone-Alpes, France by Flickr user, Regarde là-bas,https://www.flickr.com/photos/marcel_s_s/8624344496/in/pool-tbasab/
3-Band Image with 3-Band LUT.
Resultant bands recom-bined into one image.
![Page 20: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/20.jpg)
6 September 2021 1999-2021 by Richard Alan Peters II 20
Lightning at Ramasse, Rhone-Alpes, France by Flickr user, Regarde là-bas,https://www.flickr.com/photos/marcel_s_s/8624344496/in/pool-tbasab/
3-Band Image with 3-Band LUT.
A silly example to demon-strate some possibilities.
![Page 21: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/21.jpg)
Basic Point Processing:Brightness, Contrast, and Gamma
6 September 2021 1999-2021 by Richard Alan Peters II 21
![Page 22: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/22.jpg)
original + gamma- gamma + brightness- brightness
original + contrast- contrast histogram EQhistogram mod
6 September 2021 1999-2021 by Richard Alan Peters II 22
Point Processing
![Page 23: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/23.jpg)
Point Processes: Original Image
Kinkaku-ji (金閣寺, Temple of theGolden Pavilion), also known asRokuon-ji (鹿苑寺, Deer GardenTemple), is a Zen Buddhist templein Kyoto, Japan.Photo by Alan Peters, August 1993.
Luminance Histogram
6 September 2021 1999-2021 by Richard Alan Peters II 23
For more information on this fascinating, uniqueplace read the historical novel by Mishima,Yukio,The Temple of the Golden Pavilion, translated byIvan Morris, Shinchosha Publishing Co, Ltd., 1956.
![Page 24: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/24.jpg)
if , , 256, , ,, ,
if , , 255255,r c b gr c b g
r c br c b g
IIJ
I
Point Processes: Increase Brightness
0 127 255
012
725
5
g
LUT Mapping 0 and 1 2 3 is the band index.g b , ,
saturation point
6 September 2021 1999-2021 by Richard Alan Peters II 24
![Page 25: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/25.jpg)
Point Processes: Decrease Brightness
0 127 255
012
725
5LUT Mapping
255-g
0 and 1 2 3 is the band index.g b , ,
0, if , , 0, ,
, , , if , , 0r c b g
r c br c b g r c b g
IJ
I I
zero point
6 September 2021 1999-2021 by Richard Alan Peters II 25
![Page 26: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/26.jpg)
Point Processes: Decrease Contrast
( , , ) , , ,r c b a r c b s s T I
0 127 255
012
725
5LUT Mapping
where 0 1.0, s 0,1,2, , 255 , and 1, 2,3 .
a
b
Here, s = 127
s is thecenter ofthe contrastfunction.
6 September 2021 1999-2021 by Richard Alan Peters II 26
![Page 27: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/27.jpg)
Point Processes: Increase Contrast
0, if , , 0,, , , , , if 0 , , 255,
255, if , , 255.
r c br c b r c b r c b
r c b
TJ T T
T
( , , ) , ,r c b a r c b s s T I
0 127 255
012
725
5LUT Mapping 1, s 0, ,255 , 1 2 3a b , ,
zero point
sat. point
Here, s = 127
6 September 2021 1999-2021 by Richard Alan Peters II 27
![Page 28: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/28.jpg)
Point Processes: Increase Contrast
0, if , , 0,, , , , , if 0 , , 255,
255, if , , 255.
r c br c b r c b r c b
r c b
TJ T T
T
( , , ) , ,r c b a r c b s s T I
0 127 255
012
725
5LUT Mapping 1, s 0, ,255 , 1 2 3a b , ,
zero point
sat. point
Here, s = 127
6 September 2021 1999-2021 by Richard Alan Peters II 28
Steps:1. Convert image to class double2. Subtract s from image I3. Multiply result by contrast slope4. Add s back to I5. Convert to class uint8
![Page 29: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/29.jpg)
Steps to Make A Contrast LUT
6 September 2021 1999-2021 by Richard Alan Peters II 29
Double thecontrast of a 3-bitimage centered onintensity level 4
array index
(3) add 4
(1) subtract 4
(4) result
center (2) times 2
(4) 2-to-1 map8 input levels
5 output levels
8 input levels
(0) 1-to-1 map
8 output levels
![Page 30: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/30.jpg)
Point Processes: Contrast Stretch
, ,
, ,
Let min , , max , ,
min , , max x , .
, supp , , measured, , given.,
Then, , .
r c r c
r c r c
m r c M r c
m r c M r c
r c m M m Mr c m
r c M m mM m
I I
J J
I I J J
IJ J J
I I
I I
J J
II
J0 127 255
012
725
5LUT MappingmI MI
mJ
MJ zero point
sat. point
center point
6 September 2021 1999-2021 by Richard Alan Peters II 30
![Page 31: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/31.jpg)
Center Point of Contrast Stretch
, ,
, ,
I J
min , , max , ,
min , , max , ,
, supp ,
, measured, , given.
, , ,m
c , c , slope .2 2
r c r c
r c r c
m r c M r c
m r c M r c
r c
m M m MM mr c r c m mM
M m M mM mM m
I I
J J
I I J J
J JI J
I I
J J J JI I
I I
I I
J J
I
J I
6 September 2021 1999-2021 by Richard Alan Peters II 31
![Page 32: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/32.jpg)
Information Loss from Contrast Adjustment
orig
lo-c
hi-c
histograms
6 September 2021 1999-2021 by Richard Alan Peters II 32
![Page 33: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/33.jpg)
Information Loss from Contrast Adjustmentorig
orig
orig
lo-c hi-c
lo-c
hi-c
rest
rest
lo-c
hi-c
diff
diff
abbreviations:originallow-contrasthigh-contrastrestoreddifference
difference betweenoriginal and restoredlow-contrast
difference betweenoriginal and restoredhigh-contrast
6 September 2021 1999-2021 by Richard Alan Peters II 33
![Page 34: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/34.jpg)
Point Processes: Increased Gamma
0 127 255
012
725
5LUT mapping
1
,, 255 for 1.0
255r c
r c
IJ
6 September 2021 1999-2021 by Richard Alan Peters II 34
![Page 35: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/35.jpg)
Point Processes: Decreased Gamma
0 127 255
012
725
5LUT mappingm M
1,
, 255 for 0 < 1.0255r c
r c
IJ
6 September 2021 1999-2021 by Richard Alan Peters II 35
![Page 36: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/36.jpg)
Point Processes: Decreased Gamma
0 127 255
012
725
5LUT mappingm M
1,
, 255 for 0 < 1.0255r c
r c
IJ
6 September 2021 1999-2021 by Richard Alan Peters II 36
Rather than rather than 255[I/255]1/, gamma correction can also bedefined as 255[I/255]. The effects are opposite. That definition isoften used for image processing as a precursor to coding fortransmission. (https://en.wikipedia.org/wiki/Gamma_correction.)
![Page 37: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/37.jpg)
Gamma Correction: Effect on Histogram
6 September 2021 1999-2021 by Richard Alan Peters II 37
![Page 38: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/38.jpg)
Are LUTs Faster than Direct Computation?
6 September 2021 1999-2021 by Richard Alan Peters II 38
For most computational applications, LUTs are faster than directcomputation, especially when the LUTs are implemented inhardware – e.g. in the frame buffer of a device driver.
In a compiled language, indirect addressing is, I believe, fasterthan arithmetic.1 If so LUTs should be faster than directcomputation.
What about for Matlab?
1I think this is true. But I have not tested it. If anyone would like to test it, I would like to know if I am right or wrong!
![Page 39: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/39.jpg)
Are LUTs Faster than Direct Computation?
6 September 2021 1999-2021 by Richard Alan Peters II 39
Example: Increase brightness of a 24-bit image.
% brightness increase by 32LUTbi = LUT + 32; % since class(LUT) == uint8, LUT(n) == 255 for n > 223J = I + 32; % since class(I) == uint8, J(r,c,b) == 255 for I(r,c,b) > 222K = LUTbi(I+1); % K has the same number of rows columns, and bands as I
I = imread(‘24-bit image file name’);% initialize LUTLUT = uint8(0:255);
Matlab averages over 100 trialsDirect computation: 0.00054486sMap through LUT: 0.057614sDirect/LUT ratio: 0.0094569Direct computation is 105.7425 faster than LUT.
Not in this case, using MATLAB.
![Page 40: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/40.jpg)
Are LUTs Faster than Direct Computation?
6 September 2021 1999-2021 by Richard Alan Peters II 40
Example: Increase contrast of a 24-bit image.
% linear slope in intensity from 0 to 255 over 31 to 223% (LUT indices 32 to 224)LUTct = (LUT-31)*(255/(223-31)); % contrast increase in LUTJ = (I - 31)*(255/(223-31)); % contrast increase of IK = LUTct(I+1); % both J and K are clipped at intensities 0 and 255
I = imread(‘24-bit image file name’);% initialize LUTLUT = uint8(0:255);
Matlab averages over 100 trialsDirect computation: 0.0092743sMap through LUT: 0.057524sDirect/LUT ratio: 0.16123Direct computation is 6.2025 faster than LUT.
Not in this case, using MATLAB.
![Page 41: EECE/CS 4353 Image Processing - Internet Archive](https://reader031.vdocuments.net/reader031/viewer/2022022820/621c2dc38ce8e063bd7d6736/html5/thumbnails/41.jpg)
Are LUTs Faster than Direct Computation?
6 September 2021 1999-2021 by Richard Alan Peters II 41
% sigmoid function see slide 13a = 2;x = 0:255;LUTsi = uint8(255 ./ (1+exp(-a*(x-127)/32))); % no actual clipping in …J = uint8(255 ./ (1+exp(-a*(double(I)-127)/32))); % … J or K but …K = LUTsi(I+1); % … intensities < 28 are mapped to 0 and > 226 map to 255
Matlab averages over 100 trialsDirect computation: 0.035263sMap through LUT: 0.060322sDirect/LUT ratio: 0.58458Direct computation is 1.7106 faster than LUT.
Not in this case, using MATLAB.
Example: Map a 24-bit image through a sigmoid function.I = imread(‘24-bit image file name’);% initialize LUTLUT = uint8(0:255);