digital image processing practice 3
TRANSCRIPT
![Page 1: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/1.jpg)
Digital Image ProcessingPractice 3
Atsushi OsaYamaguchi Univ.
![Page 2: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/2.jpg)
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
![Page 3: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/3.jpg)
• Let’s watch the video for Practice 3.
• You may close the Webex window as it will interfere with the exercise.
• Visit the Webex meeting when you need it.
3
![Page 4: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/4.jpg)
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-p3.pdf2.Materials: dip-m3.zip
3
![Page 5: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/5.jpg)
Preparation 2
1. Open your “Documents” folder, and insideopen the “processing” folder.
2. Decompress the “dip-m3.zip” file.3. Move the “dip-m3” folder inside the
“processing” folder.
5
![Page 6: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/6.jpg)
Today’s topics
• Histogram• Contrast change• Automatic gain control
![Page 7: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/7.jpg)
Histogram• The histogram of a digital image with intensity
levels within the range [0,L-1] is a discrete function h(rk) = nk, where rk is the k thintensity value and nk is the number of pixels in the image with intensity rk.
nk
rk0 1 2 3 252 253 254 255
n0
n1n2
n3
・・・
n255
L-1
![Page 8: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/8.jpg)
Exercise 3.1:
Q. What is the summation of nk within the range [0,L-1] ?
A.
![Page 9: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/9.jpg)
Exercise 3.1: Answer
Q. What is the summation of nk within the range [0,L-1] ?
A. The total number of pixels in the image
M rows
N columns
∑−
=
×=1
0
L
kk NMn
![Page 10: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/10.jpg)
Histogram
A histogram shows the basic intensity characteristics of an image: dark, light, low contrast, and high contrast.
![Page 11: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/11.jpg)
Exercise 3.2
• Load the “ex3_2” sketch.• Run the sketch.
![Page 12: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/12.jpg)
Histogram
Input image: f(x,y)
inImage[x][y] in this sketch.
Output image: g(x,y)
outImage[x][y] in this sketch
Histogram of the input image
Histogram of the output image
0rk 255
Attention! Black pixels only in these images
Intensity level: you can select the level
Number of pixels: 200 (width) x 200 (height)
equal
![Page 13: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/13.jpg)
Histogram
nk
rk0 1 2 3 252 253 254 255
n0=40000
n1=0
n2=0・・・
n3=0
nk=0 n255=0
![Page 14: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/14.jpg)
Exercise 3.3
• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
String fileName=“black.bmp”;
String fileName=“gradation.bmp”;
![Page 15: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/15.jpg)
Histogram of a gradation image
Input image: f(x,y)
inImage[x][y] in this sketch.
Output image: g(x,y)
outImage[x][y] in this sketch
Histogram of the input image
Histogram of the output image
0rk 255
All gray levels have the same number of pixels.
Flat
![Page 16: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/16.jpg)
Exercise 3.4
• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
String fileName=“gradation.bmp”;
String fileName=“sunflower.bmp”;
![Page 17: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/17.jpg)
Histogram of a high-contrast image
0rk 255
![Page 18: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/18.jpg)
Exercise 3.5: Answer the correct combinations between the images and histograms
0 rk255
A B C D
α
β
γ
δ
A
B
C
D
![Page 19: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/19.jpg)
Send your answers by e-mail now
Pause the video until you send your answers to me.
19
![Page 20: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/20.jpg)
Exercise 3.6
• Change the code as follows:
• Save the sketch as a new name.• Run the sketch.
String fileName=“sunflower.bmp”;
String fileName=“sunflower0.bmp”;
![Page 21: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/21.jpg)
Histogram of a dark image
0rk 255
![Page 22: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/22.jpg)
Exercise 3.7
• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
String fileName=“sunflower0.bmp”;
String fileName=“sunflower1.bmp”;
![Page 23: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/23.jpg)
Histogram of a light image
0rk 255
![Page 24: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/24.jpg)
Exercise 3.8
• Change the code as follows:
• Save the sketch with a new name.• Run the sketch.
String fileName=“sunflower1.bmp”;
String fileName=“sunflower2.bmp”;
![Page 25: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/25.jpg)
Histogram of a low-contrast image
0rk 255
![Page 26: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/26.jpg)
Histogram Processing
Histogram manipulation can be used for image enhancement.
![Page 27: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/27.jpg)
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)
![Page 28: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/28.jpg)
Contrast stretching• Contrast stretching expands the range of
intensity levels in an image so that it spans the full intensity range of the recording medium or display device.
input image: f
outp
ut im
age:
g
0 255
255
0
outp
ut im
age:
g
0 255
255
0
input image: f
Identitytransformation
Contrast stretching
f1 f2
![Page 29: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/29.jpg)
Contrast stretchingrange [0,f1] in input image f
range [f1,f2]
range[f2,255]outp
ut im
age:
g
0 255
255
0
input image: f
Contrast stretching
f1 f2
0=g
( )112
255 ffff
g −−
=
255=g
![Page 30: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/30.jpg)
Exercise 3.9
• Read the sketch for exercise 3.8 (low-contrast). • Change the code as follows:
• Save the sketch as a new name.• Run the sketch.
void imageProcessing(){for (int x = 0; x < imageWidth; x++ ) {
for (int y = 0; y < imageHeight; y++ ) {outImage[x][y] = inImage[x][y];
}}
}next page
![Page 31: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/31.jpg)
Exercise 3.9: Step 1void imageProcessing(){
float f1 = 100;float f2 = 150;for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
if(inImage[x][y]<f1){
}if(inImage[x][y]>=f1 && inImage[x][y]<=f2){
} if(inImage[x][y]>f2){
}}
}}
outp
ut im
age:
g
0 255
255
0
input image: f
f1 f2
question 1 of step 1
I will ask you in Step2
question 2 of step 1Logic Operation
AND
![Page 32: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/32.jpg)
If statement
if(inImage[x][y]<f1){
}
1.Test thisif trueif false
2.Run codes inside these curly brackets
exit
![Page 33: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/33.jpg)
Exercise 3.9: answer of Step 1void imageProcessing(){
float f1 = 100;float f2 = 150;for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
if(inImage[x][y]<f1){outImage[x][y]=0;
}if(inImage[x][y]>=f1 && inImage[x][y]<=f2){
} if(inImage[x][y]>f2){
outImage[x][y]=255;}
}}
}
I will ask you in Step2
![Page 34: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/34.jpg)
Exercise 3.9: Step 2void imageProcessing(){
float f1 = 100;float f2 = 150;for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
if(inImage[x][y]<f1){outImage[x][y]=0;
}if(inImage[x][y]>=f1 && inImage[x][y]<=f2){
} if(inImage[x][y]>f2){
outImage[x][y]=255;}
}}
}
Answer the correct code
![Page 35: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/35.jpg)
• Send your answer by e-mail
• Pause the video until you send your answers to me.
![Page 36: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/36.jpg)
Answervoid imageProcessing(){
float f1 = 100;float f2 = 150;for(int y=0;y<imageHeight;y++){for(int x=0;x<imageWidth;x++){
if(inImage[x][y]<f1){outImage[x][y]=0;
}if(inImage[x][y]>=f1 && inImage[x][y]<=f2){
outImage[x][y]=(255/(f2-f1))*(inImage[x][y]-f1);} if(inImage[x][y]>f2){
outImage[x][y]=255;}
}}
}
( )112
255 ffff
g −−
=
![Page 37: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/37.jpg)
Exercise 3.10
• Change the code as follows:
• Change the values of two variables f1 and f2 in order to obtain a high-contrast image.
• Save the sketch with a new name.• Run the sketch.
String fileName=“sunflower2.bmp”;
String fileName=“sunflower0.bmp”;
float f1 = 100;float f2 = 150;
dark image
![Page 38: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/38.jpg)
Ideal f1 and f2 for this image
float f1 = 14;float f2 = 92;
14 92
![Page 39: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/39.jpg)
Exercise 3.11
• Change the code as follows:
• Change the values of the two variables f1 and f2 in order to obtain a high-contrast image.
• Save the sketch with a new name.• Run the sketch.
String fileName=“sunflower0.bmp”;
String fileName=“sunflower1.bmp”;
float f1 = 100;float f2 = 150;
light image
![Page 40: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/40.jpg)
Ideal f1 and f2 for this image
float f1 = 180;float f2 = 241;
180 241
![Page 41: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/41.jpg)
Automatic Gain Control (AGC)
• To find suitable values of f1 and f2 automatically,
nk s are zero in the range [0, min-1] nk s are zero in the range [max+1, 255]min max
![Page 42: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/42.jpg)
Exercise 3.12
• Load the sketch for exercise 3.11. • Change the code as shown on the next slide.• Save the sketch with a new name.• Run the sketch.
![Page 43: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/43.jpg)
void imageProcessing(){float f1 = 100;float f2 = 200;for(int y=0;y<imageHeight;y++){
for(int x=0;x<imageWidth;x++){if(inImage[x][y]<f1){
outImage[x][y]=0;}
if(inImage[x][y]>=f1 && inImage[x][y]<=f2){outImage[x][y]=(255/(f2-f1))*(inImage[x][y]-f1);
} if(inImage[x][y]<f2){
outImage[x][y]=255;}
}}}
float f1=0;float f2=255;for(int i=0;i<256;i++){if(inHistogram[i]>0){f1=i;break;
}}for(int i=255;i>=0;i--){if(inHistogram[i]>0){f2=i;break;
}}
Exercise 3.11
Exercise 3.12
Searching the min and max
![Page 44: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/44.jpg)
Exercise 3.13:
• Change the name of the input image to these other files.
• Save the sketch with a new name.• Run the sketch.
String fileName=“sunflower0.bmp”;
String fileName=“sunflower2.bmp”;
![Page 45: Digital Image Processing Practice 3](https://reader031.vdocuments.net/reader031/viewer/2022022822/621c32df2c7f982c5b261d63/html5/thumbnails/45.jpg)
• That’s all for today.• You may close today’s Webex meeting.• If you have any questions, please ask me by
the Webex meeting or e-mail.