Depth Image Coding & Processing Part 3: Depth Image Processing
L24. More on Image File Processing
description
Transcript of L24. More on Image File Processing
![Page 1: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/1.jpg)
L24. More on Image File Processing
Filtering Noise
Edge Detection
![Page 2: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/2.jpg)
Pictures as Arrays
A black and white picture can be encodedas a 2D Array
Typical: 0 <= A(i,j) <= 255 (black) (white)
Values in between correspond to differentlevels of grayness.
![Page 3: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/3.jpg)
1458-by-2084
150 149 152 153 152 155 151 150 153 154 153 156 153 151 155 156 155 158 154 153 156 157 156 159 156 154 158 159 158 161 157 156 159 160 159 162
Just a Bunch of Numbers
![Page 4: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/4.jpg)
1458-by-2084
150 149 152 153 152 155 151 150 153 154 153 156 153 2 3 156 155 158 154 2 1 157 156 159 156 154 158 159 158 161 157 156 159 160 159 162
Dirt!
Note how the“dirty pixels”look out of place
![Page 5: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/5.jpg)
Can We Filter Out the “Noise”?
![Page 6: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/6.jpg)
1458-by-2084
150 149 152 153 152 155 151 150 153 154 153 156 153 ? ? 156 155 158 154 ? ? 157 156 159 156 154 158 159 158 161 157 156 159 160 159 162
Idea
Assign “typical”neighborhoodgray values to “dirty pixels”
![Page 7: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/7.jpg)
Getting Precise
“Typical neighborhood gray values”
Could useMedian
Or Mean
radius 1 radius 3
We’ll look at “Median Filtering” first…
![Page 8: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/8.jpg)
Median Filtering
Visit each pixel.
Replace its gray value by the medianof the gray values in the
“neighborhood”.
![Page 9: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/9.jpg)
Using a radius 1 “Neighborhood”
6
7
6
7
6
7
7
6
6
6
7
6
7
0
7
7
6
6
Before After
066667777
![Page 10: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/10.jpg)
How to Visit Every Pixel
m = 9
n = 18
for i=1:m for j=1:n Compute new gray value for pixel (i,j). endend
![Page 11: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/11.jpg)
i = 1
j = 1
Original:
Filtered:
Replace with the median of the values under the window.
![Page 12: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/12.jpg)
i = 1
j = 2
Original:
Filtered:
Replace with the median of the values under the window.
![Page 13: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/13.jpg)
i = 1
j = 3
Original:
Filtered:
Replace with the median of the values under the window.
![Page 14: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/14.jpg)
i = 1
j = n
Original:
Filtered:
Replace with the median of the values under the window.
![Page 15: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/15.jpg)
i = 2
j = 1
Original:
Filtered:
Replace with the median of the values under the window.
![Page 16: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/16.jpg)
i = 2
j = 2
Original:
Filtered:
Replace with the median of the values under the window.
![Page 17: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/17.jpg)
i = m
j = n
Original:
Filtered:
Replace with the median of the values under the window.
![Page 18: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/18.jpg)
What We Need…
(1) A function that computes the medianvalue in a 2-dimensional array C:
m = medVal(C)
(2) A function that builds the filteredimage by using median values of radius
rneighborhoods:
B = medFilter(A,r)
![Page 19: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/19.jpg)
Computing Medians
21 89 36 28 19 88 43x :
x = sort(x)
19 21 28 36 43 88 89x :
n = length(x); % n = 7m = ceil(n/2); % m = 4med = x(m); % med = 36
If n is even, then use : med = ( x(m) + x(m+1) )/2
![Page 20: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/20.jpg)
Median of a 2D Array
function med = medVal(C)
[p,q] = size(C);
x = [];
for k=1:p
x = [x C(k,:)];
end
Compute median of x and assign to med.
![Page 21: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/21.jpg)
Medians vs Means
A = 150 151 158 159 156 153 151 156 155 151 150 155 152 154 159 156 154 152 158 152 152 158 157 150 157
Median = 154 Mean = 154.2
![Page 22: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/22.jpg)
Medians vs Means
A = 150 151 158 159 156 153 151 156 155 151 150 155 0 154 159 156 154 152 158 152 152 158 157 150 157
Median = 154 Mean = 148.2
![Page 23: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/23.jpg)
Back to Filtering…
m = 9
n = 18
for i=1:m for j=1:n Compute new gray value for pixel (i,j). endend
![Page 24: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/24.jpg)
Window Inside…
m = 9
n = 18
New gray value for pixel (7,4) = medVal( A(6:8,3:5) )
![Page 25: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/25.jpg)
Window Partly Outside…
m = 9
n = 18
New gray value for pixel (7,1) = medVal( A(6:8,1:2) )
![Page 26: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/26.jpg)
Window Partly Outside…
m = 9
n = 18
New gray value for pixel (9,18) = medVal( A(8:9,17:18) )
![Page 27: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/27.jpg)
function B = medFilter(A,r) % B from A via median filtering % with radius r neighborhoods. [m,n] = size(A); B = uint8(zeros(m,n)); for i=1:m for j=1:n C = pixel (i,j) neighborhood
B(i,j) = medVal(C); end end
![Page 28: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/28.jpg)
The Pixel (i,j) Neighborhood
iMin = max(1,i-r)
iMax = min(m,i+r)
jMin = max(1,j-r)
jMax = min(n,j+r)
C = A(iMin:iMax,jMin:jMax)
r = 1 r = 2
Am
n
![Page 29: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/29.jpg)
B = medFilter(A)
![Page 30: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/30.jpg)
Original
![Page 31: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/31.jpg)
What About Using the Meaninstead of the Median?
Replace each gray value with theaverage gray value in the radius rneighborhood.
![Page 32: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/32.jpg)
Mean Filter with r = 3
![Page 33: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/33.jpg)
Mean Filter with r = 10
![Page 34: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/34.jpg)
Why it Fails
150 149 152 153 152 155 151 150 153 154 153 156 153 2 3 156 155 158 154 2 1 157 156 159 156 154 158 159 158 161 157 156 159 160 159 162
85 8687 88
The mean does notcapture representativevalues.
![Page 35: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/35.jpg)
And Median Filters LeaveEdges (Pretty Much) Alone
200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 100 200 200 200 100 100 100 200 200 100 100 100 100 200 100 100 100 100 100
Inside the box, the 200’s stay at 200 and the 100’s stay at 100.
![Page 36: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/36.jpg)
Finding Edges
![Page 37: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/37.jpg)
What is an Edge?Near an edge, grayness values changeabruptly.
200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 100 200 200 200 100 100 100 200 200 100 100 100 100 200 100 100 100 100 100
![Page 38: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/38.jpg)
The Rate-of-Change-Array
Suppose A is an image array with integervalues between 0 and 255
B(i,j) be the maximum difference betweenA(i,j) and any of its eight neighbors.
![Page 39: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/39.jpg)
Example
59
90
58
60
56
62
65
57
81Rate-of-change at middle pixel is 30
![Page 40: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/40.jpg)
function B = Edges(P)% P is a jpeg file% B is the corresponding % Rate-Of-Change array A = rgb2gray(imread(P)); [m,n] = size(A); B = uint8(zeros(m,n)); for i=2:m-1 for j = 2:n-1 B(i,j) = ????? end end
![Page 41: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/41.jpg)
Recipe for B(i,j)% The 3-by-3 subarray that includes
% A(i,j) and its 8 neighbors…
Neighbors = A(i-1:i+1,j-1:j+1);
% Subtract A(i,j) from each entry…
Diff = Neighbors – A(i,j));
% Take absolute value of each entry..
posDiff = abs(Diff);
% Compute largest value in each column…
colMax = max(posDiff);
% Compute the max of the column max’s…
B(I,j) = max(colMax)
![Page 42: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/42.jpg)
Rate-of-Change Array to Image
B = Edges('Tower.jpg');
% Compute 0-1 array that identifies
% those B entries bigger than 20:
importantPixels = B > 20;
% Display those pixels with maximum
% brightness
C = uint8( 255*importantPixels );
imshow(C)
B>0 is a 0-1 array, the ones are located where B(i,j)> 20.
![Page 43: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/43.jpg)
Threshhold = 40
![Page 44: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/44.jpg)
Threshhold = 20
![Page 45: L24. More on Image File Processing](https://reader031.fdocuments.us/reader031/viewer/2022020117/56814037550346895daba355/html5/thumbnails/45.jpg)
Threshhold = 30