digital image processing practice 2
TRANSCRIPT
How to attend this on-line practice1. Download materials for the practice from the course web
site of Digital Image Processing: – http://ds.cc.yamaguchi-u.ac.jp/~samura/web-login/DIP/
2. Watch a video for this practice (on-demand service) indicated in the course web site.
3. Send me your answers for some exercises by e-mail. They are indicated in the video and the slideshow.
4. When you finish today’s exercises, you may close this Webex meeting.
5. The Webex meeting will be closed at the end of the practice.
2
• Let’s watch the video for Practice 2.
• You may close the Webex window as it will interfere with the exercise.
• Visit the Webex meeting when you need it.
3
Preparation 1-download materials-
Download materials for today’s practice from the course web site: http://ds.cc.yamaguchi-u.ac.jp/~samura/web-login/DIP/
1.Slideshow: dip-p2.pdf2.Materials: dip-m2.zip
3
Preparation 2
1. Open your “Documents” folder, and insideopen the “processing” folder.
If you are unable to find the “processing” folder inyour “Documents” folder, execute“processing.exe” again. Next, open your“Documents” folder.
2. Decompress the “dip-m2.zip” file.3. Move the “dip-m2” folder inside the
“processing” folder.6
Today’s topics
• Explanation of the homework
• Quantization and image matrix.• Basic intensity transformation
– Image negatives– gamma transformation– etc.
Homework of Practice 1
Questions:When you shrink the image “pattern1.bmp,” you
will find various patterns that differ from theoriginal image.
1. What are these patterns?2. Why does the image show these strange
patterns when zooming-out?
9
An example of answer
• Aliasing or moiré• Zoom-out (shrinking) may be viewed as under-
sampling, and the aliasing occurred in thepicture. This phenomena is explained by thesampling theorem.
10
11of95
Shared Lecture 2015 Digital Image Processing
Image Aliasing Example
Left: Adequately sampled imageAbove center: Image sub-sampled by 50%Above right: Image sub-sampled by 25%
More aliasing occurs at the periphery since the image frequency is higher and the sampling rate is inadequate.
Less aliasing occurs near the center since the frequency is lower and the sampling rate adequate.
Sampling theorem
• When the sampling frequency don’t satisfy the Nyquist criterion, we call this sampling condition as “under sampling.”
13
Nyquist criterionBfs 2≥
Spatial sampling frequency
The highest spatial frequencyof an original signal
Bsf
Intensity resolutionIn the quantization process,
the intensity resolution is determined by the intensity level, which is an integer power of two, 2n.
The most common number nis 8 bits, with 16 bits being used in some applications in which an enhancement of the specific intensity ranges is necessary.
28 = 256
0 1 2 127 255253254
・・・ ・・・
01234567
24
Image matrix• Suppose that we sample a continuous image
into a 2-D array, f(x,y), containing M rows and Ncolumns, where (x, y) are discrete coordinates.
Sampling &Quantization
f(x, y)
M rows
N columns
Image matrix• f(x,y) is represented as a matrix of numerical
values that indicate the intensity of the image.
f(x, y)
M rows
N columns
f(0, 0) f(1,0) f(N-1,0)
f(0, 1)
f(0,N-1)
f(N-1,N-1)
255 255 255 255 ・ 255 255
255 255 255 255 ・ ・
255 255 255 0
255 255 255 50 ・
・ 50 100 ・
255 ・ ・ ・ 255
255 255 255 ・ ・ 255 255
Image shown as a numerical matrixf(x, y)
Exercise 2.2• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
void imageProcessing(){
}
void imageProcessing(){outImage[100][100]=255;
}
Exercise 2.3• Change the code as follows:
void imageProcessing(){outImage[100][100]=255;outImage[101][100]=255;outImage[100][101]=255;outImage[101][101]=255;
}
• Change the code as follows:
• Save the sketch as a new name.• Run the sketch.
Exercise 2.4
• Change the code as follows:
• Save the sketch as a new name.• Run the sketch.
void imageProcessing(){for(int x=0;x<imageWidth;x++){
outImage[x][100]=255;}
}
“for” loop
for(int x=0;x<imageWidth;x++){outImage[x][100]=255;
}
1. Start withthis
2. Test thisif trueif false
3.Run this code
4.Do this
5. Return to #2
exit
• “imageWidth” means the width of the image. Currently, it is 200.
• “x++” means “add 1 to x “
Exercise 2.5
• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
void imageProcessing(){for(int x=0;x<imageWidth;x++){
outImage[x][100]=x;}
}
Exercise 2.6• Create the right
output image using “for” loops. The height of the image is referred to as a variable “imageHeight.”
• Hint: • for(int y=0;y<imageHeight;y++)
Fill in the correct codeand send your answer by e-mail
25
void imageProcessing(){
}
?
Pause the video until you send your answers to me.
Answer to Exercise 2.6
void imageProcessing(){for(int y=0;y<imageHeight;y++){
for(int x=0;x<imageWidth;x++){outImage[x][y]=x;
}}
}
Spatial Operations
Spatial domain techniques operate directly at the pixels of an image.
T: transform function.f(x,y): input imageg(x,y): output image.
g(x, y) = T [ f(x, y)]
Image matrix in the sketch
Input image: f(x,y)
inImage[x][y] in this sketch.
Output image: g(x,y)
outImage[x][y] in this sketch
Exercise 2.7
• Load the “ex2_1” sketch.• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
void imageProcessing(){for(int y=0;y<imageHeight;y++){
for(int x=0;x<imageWidth;x++){outImage[x][y]=inImage[x][y];
}}
}
String fileName=“black.bmp”; → String fileName=“sunflower.bmp”;
Intensity transformation functionof exercise 2.7
f(x,y): input imageg(x,y): output image
g(x, y) = f(x, y)
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
outImage[x][y]=inImage[x][y];}
}}
Identity transformation
Exercise 2.8
• Load the sketch for exercise 2.7. • Create a sketch that operates the transform
function,
• Save the sketch with a new name.• Run the sketch.• Then, change the sketch that operates the
transform function,
g(x, y) = f(x, y)+50.
g(x, y) = f(x, y)-50.
Fill in the correct codeand send your answer by e-mail
32
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
}}
}
?
Pause the video until you send your answers to me.
Answer
33
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
outImage[x][y]=inImage[x][y] + 50;}
}}
g(x, y) = f(x, y) + 50;
Answer
34
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
outImage[x][y]=inImage[x][y] - 50;}
}}
g(x, y) = f(x, y) - 50;
Basic intensity transformation functionIdentity transformation
Negative transformation
Logarithmic transformation
Power-Law (Gamma) transformation
f
g
g(x, y) = f(x, y)
g(x, y) = L-1 -f(x, y)
i.e. g(x, y) = 255 -f(x, y)
g(x, y) = C log( f(x, y) )
g(x, y) = C f γ(x, y)
Exercise 2.9
• We want to make a negative of an image with intensity levels within the range [0, 255].
• Create a sketch for this negative transformation.
f
g
Fill in the correct codeand send your answer by e-mail
37
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
}}
}
?
Pause the video until you send your answers to me.
Answer
38
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
outImage[x][y] = 255 - inImage[x][y];
}}
}
g(x, y) = 255 - f(x, y)
Negative transformation
Exercise 2.10: Gamma transformation
• We want to create a sketch that operates the power-law (Gamma) transformation g(x, y) = C f γ(x, y)
When f(x,y) = 255, we have to obtain g(x,y) = 255.Therefore,
),(),(yxf
yxgC γ=
γγ 255255
),(),(==
yxfyxgC
Homework (Exercise 2.10):Fill in the correct code
• Load the sketch for exercise 2.7. • Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
void imageProcessing(){for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
float gamma = 0.5;
}}
}
?
Hint:255gamma
is written aspow(255, gamma)
Send your answer by e-mail later
deadline: Oct. 18, 15:10
• It’s over for today.• You may close today’s Webex meeting.• If you have any questions, please ask me by
the Webex meeting or e-mail.41