Summary of Lecture 1: "Let There Be Light"
Summary of Lecture 1: "Let There Be Light"
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 1
Images as Matrices
• An image matrix (N × M ):
A(0, 0) A(0, 1) A(0, 2) . . . A(0, M − 1)
A(1, 0) A(1, 1) A(1, 2) . . . A(1, M − 1)
A=
..
N rows
A(N − 1, 0) A(N − 1, 1) A(N − 1, 2) . . . A(N − 1, M − 1)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 2
Simple Processing - Transpose
A B
>> for i = 1 : 512
for j = 1 : 512
B(j, i) = A(i, j); OR >> B = A0 ;
end
end
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 3
Simple Processing - Flip Vertical
A B
>> clear B;
>> for i = 1 : 512
for j = 1 : 512
B(i, 512 + 1 − j) = A(i, j);
end
end
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 4
Simple Processing - Cropping
• The cropped image B (N1 × N2) of A (N × M ), starting from (n1, n2), can
be obtained as B(k, l) = A(n1 + k, n2 + l) (k = 0, . . . , N1 − 1, l = 0, . . . , N2 − 1).
A B
>> clear B;
>> for k = 0 : 64 − 1
for l = 0 : 128 − 1
B(k + 1, l + 1) = A(255 + k + 1, 255 + l + 1); % n1=n2=255 N1=64,N2=128
end
end
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 5
Cropping as a Matlab Function
for k = 0 : N 1 − 1
for l = 0 : N 2 − 1
B(k + 1, l + 1) = A(n1 + k + 1, n2 + l + 1);
end
end
function [B] =mycrop(A, n1, n2, N 1, N 2)
% mycrop.m
% [B] =mycrop(A, n1, n2, N 1, N 2)
% crops the image A from location n1, n2
% with size N 1, N 2
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 6
Simple Image Statistics - Sample Mean and Sample
Variance
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 7
Simple Image Statistics - Histogram
• Note that:
255
X
hA(l) = Number of pixels in A (4)
l=0
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 8
Calculating the Histogram
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 9
Example I
A hA (l)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 10
Example II
A hA (l)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 11
Example III
A hA (l)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 12
Point Processing
• The function g(l) operates on each image pixel or each image point
independently.
• In general the resulting image g(A(i, j)) may not be an image matrix,
i.e., it may be the case that g(A(i, j)) 6∈ {0, . . . , 255} for some (i, j).
• Thus we will have to make sure we obtain an image B that is an image
matrix.
• The histograms hA(l) and hB (l) will play important roles.
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 13
Identity point function
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 14
Digital Negative
B hB (l)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 15
Digital Negative Contd.
hA(l) hB (l)
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 16
Calculating the Histogram of Point Processed Images
• For a given point function g(l), “the inverse point function” g −1(k) may
not exist.
• So in general hB (g(l)) 6= hA(l).
• Let Sg−1(k) = {l | g(l) = k, l = 0, . . . , 255} (k = 0, . . . , 255).
• Then:
X
hB (k) = hA(l), k = 0, . . . , 255 (6)
l∈Sg −1 (k)
• You must learn how to calculate and sketch hB (l) given hA(l) and the
point function g(l).
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 17
Square-root point function
√
• Let g(l) = l (l = 0, . . . , 255).
B(i, j) = g(A(i, j)), i = 0, . . . , N − 1, j = 0, . . . , M − 1
r
= A(i, j)
• In this case g(A(i, j)) 6∈ {0, . . . , 255} and we must ensure B is an image
matrix by further processing.
• We can try “rounding” g(A(i, j)) to integers by defining a new point
function g2(l) = round(g(l)):
B(i, j) = g2(A(i, j)), i = 0, . . . , N − 1, j = 0, . . . , M − 1
r
= round( A(i, j)) (>> B = round(A.ˆ(.5)); )
but that will not exactly yield what we want as we shall see.
• We will return to this example after we learn Contrast Stretching.
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 18
Contrast Stretching
α1l,
0 ≤ l < a1
g(l) =
α2(l − a1) + α1a1, a 1 ≤ l < a2 (7)
α3 (l − a2 ) + (α2 (a2 − a1 ) + α1 a1 ), a2 ≤ l ≤ 255
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 19
Example - Square-root
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 20
Piecewise Linear, “Continuous” Point Functions
• Let α0 = a0 = 0.
α1l, 0 ≤ l < a1
α2(l − a1) + α1a1, a1 ≤ l < a 2
g(l) = ..
(8)
Pi−1
α i (l − a i−1 ) + ( j=1 αj (aj − aj−1 )), ai−1 ≤ l < ai
..
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 21
A “Discontinuous” Point Function
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 22
Normalizing an Image
• Convention:
A ⇒ processing ⇒ B ⇒ “normalize B”⇒ C(i, j) = gsB (B(i, j)).
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 23
More Range Stretching/Compression
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 24
Example
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 25
Example - contd.
• Specific range stretching/compression might yield even better results. This is an effective tool to
visualize things quickly. Different problems can be tackled in the same spirit by utilizing point
functions based on log10 (. . .), log10 (log10 (. . .)), e... and so on.
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 26
“Slicing”
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 27
Thresholding
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 28
Summary
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 29
Homework Rules
• Homeworks will be read as opposed to check-marked.
• Remember that I have been doing this for a while. I usually can tell what kind of processing an
image underwent.
• Label all axis for plots and bars. Put a descriptive title on plots, bars and images.
• Be neat and always show the original image in a homework for easy comparison to processed
images.
• All utilized matlab scripts must be handed in with the homework.
• Try to conserve paper by organizing what you hand in.
• Write general matlab scripts and functions so that you can reuse them in the future. Try to make
them “bullet-proof” so that you avoid mistakes.
• Matlab scripts/functions must be commented with descriptive help information.
• When showing images, use the image, colormap(gray(256)), and axis(’image’) commands. There
is a command in matlab (imagesc) that does some automatic normalization. Do not use the
command imagesc.
• Remember the best way to view the notes and to work in matlab is after you have set your desktop
to 24 or 32 bits color depth. Otherwise you may see artificial artifacts.
• When instructed to give “brief comments”, “brief explanations” or “brief comparisons”, etc. please
be brief and to the point.
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 30
Homework II
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 31
Figure 1: Homework question 7
References
[1] A. K. Jain, Fundamentals of Digital Image Processing. Englewood Cliffs, NJ: Prentice Hall, 1989.
c Onur G. Guleryuz, Department of Electrical and Computer Engineering, Polytechnic University, Brooklyn, NY
° 32