image processing

Multimedia Programming 03:
Point Processing
Departments of Digital Contents
Sang Il Park
Outline
• Review
• Image Processing
– Brightness
– Contrast
– Gamma
• QnA for the program assignment #1
Review
•
•
•
•
•
•
•
•
•
•
•
IplImage
cvLoadImage (file_name)
cvCreateImage (size, depth, channels)
cvSaveImage (file_name, image)
cvReleaseImage (image)
cvNamedWindow (window_name)
cvShowImage (window_name, image)
cvDestroyWindow (window_name)
int cvWaitKey (delay)
Scalar cvGet2D (image, y, x)
cvSet2D (image, y, x, Scalar)
Review: HelloCV2.cpp
•
•
•
•
int main(int argc, CHAR* argv[])
{
IplImage * img;
img = cvLoadImage("d:\\test.jpg");
•
•
•
cvNamedWindow("window");
cvShowImage("window", img);
cvWaitKey();
•
•
IplImage * img2;
img2 = cvCreateImage(cvSize(300,300), IPL_DEPTH_8U, 3);
•
•
•
•
•
•
•
•
int x,y;
for(x=0; x<300; x++)
for(y=0; y<300; y++)
{
CvScalar s = cvGet2D(img, y,x);
s.val[0] +=80;
s.val[1] +=80; s.val[2] +=80;
cvSet2D(img2,y,x,s);
}
•
•
cvShowImage("window", img2);
cvWaitKey();
•
•
•
cvDestroyWindow("window");
cvReleaseImage(&img);
cvReleaseImage(&img2);
•
•
return 0;
}
Review: HelloCV2.cpp
•
•
IplImage * img;
img = cvLoadImage("d:\\test.jpg");
•
•
•
cvNamedWindow("window");
cvShowImage("window", img);
cvWaitKey();
Review: HelloCV2.cpp
•
•
•
•
int main(int argc, CHAR* argv[])
{
IplImage * img;
img = cvLoadImage("d:\\test.jpg");
•
•
•
cvNamedWindow("window");
cvShowImage("window", img);
cvWaitKey();
•
•
IplImage * img2;
img2 = cvCreateImage(cvSize(300,300), IPL_DEPTH_8U, 3);
•
•
•
•
•
•
•
•
int x,y;
for(x=0; x<300; x++)
for(y=0; y<300; y++)
{
CvScalar s = cvGet2D(img, y,x);
s.val[0] +=80;
s.val[1] +=80; s.val[2] +=80;
cvSet2D(img2,y,x,s);
}
•
•
cvShowImage("window", img2);
cvWaitKey();
•
•
•
cvDestroyWindow("window");
cvReleaseImage(&img);
cvReleaseImage(&img2);
•
•
return 0;
}
Review: HelloCV2.cpp
•
•
IplImage * img2;
img2 = cvCreateImage(cvSize(300,300), IPL_DEPTH_8U, 3);
•
•
•
•
•
•
•
•
int x,y;
for(x=0; x<300; x++)
for(y=0; y<300; y++)
{
CvScalar s = cvGet2D(img, y,x);
s.val[0] +=80; s.val[1] +=80; s.val[2] +=80;
cvSet2D(img2,y,x,s);
}
•
•
cvShowImage("window", img2);
cvWaitKey();
Review: HelloCV2.cpp
•
•
•
•
int main(int argc, CHAR* argv[])
{
IplImage * img;
img = cvLoadImage("d:\\test.jpg");
•
•
•
cvNamedWindow("window");
cvShowImage("window", img);
cvWaitKey();
•
•
IplImage * img2;
img2 = cvCreateImage(cvSize(300,300), IPL_DEPTH_8U, 3);
•
•
•
•
•
•
•
•
int x,y;
for(x=0; x<300; x++)
for(y=0; y<300; y++)
{
CvScalar s = cvGet2D(img, y,x);
s.val[0] +=80;
s.val[1] +=80; s.val[2] +=80;
cvSet2D(img2,y,x,s);
}
•
•
cvShowImage("window", img2);
cvWaitKey();
•
•
•
cvDestroyWindow("window");
cvReleaseImage(&img);
cvReleaseImage(&img2);
•
•
return 0;
}
Review: HelloCV2.cpp
•
•
•
cvDestroyWindow("window");
cvReleaseImage(&img);
cvReleaseImage(&img2);
Image Processing 1
Point processing
Alexei Efros
Images as functions
Alexei Efros
Image Processing
• An image processing operation typically
defines a new image g in terms of an existing
image f.
• We can transform either the range of f.
• Or the domain of f:
• What kinds of operations can each perform?
Alexei Efros
Image Processing
• image filtering: change range of image
• g(x) = h(f(x))
f
f
h
x
x
• image warping: change domain of image
• g(x) = f(h(x))
f
f
h
x
x
Alexei Efros
Image Processing
• image filtering: change range of image
• g(x) = h(f(x))
f
g
h
• image warping: change domain of image
• g(x) = f(h(x))
f
h
g
Alexei Efros
Point Processing
• The simplest kind of range transformations are
these independent of position x,y:
• g = t(f)
• This is called point processing.
• What can they do?
• What’s the form of t?
• Important: every pixel for himself – spatial
information completely lost!
Alexei Efros
output
Basic Point Processing
input
g = Af + B
A=1
B=0
picture from http://girlsgeneration.iple.com/
output
Basic Point Processing
input
g = Af + B
A=1
B>0
Brightness +
output
Basic Point Processing
input
g = Af + B
A=1
B<0
Brightness –
output
Basic Point Processing
input
g = Af + B
A>1
B=0
Contrast + (brightness +)
output
Basic Point Processing
input
g = Af + B
A>1
B<0
Contrast + (brightness -)
output
Basic Point Processing
input
g = Af + B
A<1
B>0
Contrast –
output
Basic Point Processing
input
g = Af + B
A<1
B > 0+++
Contrast – (brightness +)
A coding exercise
• Open image and adjust brightness/contrast by
pressing keyboard
example)
1 : brightness up(+10) 2: brightness down(-10)
3 : contrast up(+0.1)
4: contrast down(-0.1)
g = Af + B
output
g = input color value
f = output color value
A = contrast value (초기값 = 1)
B = brightness value (초기값 = 0)
input
Hint for the exercise
• How to get the key input?
– int cvWaitKey( int delay=0 )
waits for a pressed key. After waiting for the given delay, it
proceeds. Zero delay means waiting forever until user input.
• Delay in milliseconds.
More functions?
Power-law transformations
Image Enhancement
Example: Gamma Correction
sr

e.g. 0.25  0.52.0
sr
1/ 
http://www.cs.cmu.edu/~efros/java/gamma/gamma.html
Contrast Stretching
Programming Assignment #1
• How to compare R,G,B channels?
• No right answer
– Sum of Squared Differences (SSD):
– Will it be enough?
• Change in size
• Change in brightness
In the next class…
• Point Processing2:
– Image Histogram
– FILTER
• Blur
• Noise removal
• Unsharp
– Pixelation