Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

31
Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park

Transcript of Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Page 1: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Multimedia Programming 03:

Point ProcessingDepartments of Digital

ContentsSang Il Park

Page 2: 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

Page 3: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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)

Page 4: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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;• }

Page 5: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Review: HelloCV2.cpp

• IplImage * img;• img = cvLoadImage("d:\\

test.jpg");

• cvNamedWindow("window");• cvShowImage("window", img);• cvWaitKey();

Page 6: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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;• }

Page 7: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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();

Page 8: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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;• }

Page 9: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Review: HelloCV2.cpp

• cvDestroyWindow("window");• cvReleaseImage(&img);• cvReleaseImage(&img2);

Page 10: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Image Processing 1

Point processing

Alexei Efros

Page 11: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Images as functions

Alexei Efros

Page 12: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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

Page 13: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Image Processing

• image filtering: change range of image• g(x) = h(f(x))

f

x

hf

x

f

x

hf

x

• image warping: change domain of

image• g(x) = f(h(x))

Alexei Efros

Page 14: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Image Processing

• image filtering: change range of image• g(x) = h(f(x))

• image warping: change domain of

image• g(x) = f(h(x))

hf g

hf g

Alexei Efros

Page 15: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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

Page 16: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

picture from http://girlsgeneration.iple.com/

g = Af + B

A = 1B = 0

Page 17: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Brightness +

g = Af + B

A = 1B > 0

Page 18: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Brightness –

g = Af + B

A = 1B < 0

Page 19: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Contrast + (brightness +)

g = Af + B

A > 1B = 0

Page 20: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Contrast +

g = Af + B

A > 1B < 0 Contrast + (brightness -)

Page 21: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Contrast –

g = Af + B

A < 1B > 0

Page 22: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Basic Point Processing

input

ou

tput

Contrast – (brightness +)

g = Af + B

A < 1B > 0+++

Page 23: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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)

input

ou

tput

g = Af + B

g = input color valuef = output color value

A = contrast value ( 초기값 = 1)B = brightness value ( 초기값 = 0)

Page 24: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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.

Page 25: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

More functions?

Page 26: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Power-law transformations

Page 27: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Image Enhancement

Page 28: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Example: Gamma Correction

http://www.cs.cmu.edu/~efros/java/gamma/gamma.html

rs

/1rs

0.25.025.0.. ge

Page 29: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

Contrast Stretching

Page 30: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

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

Page 31: Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.

In the next class…

• Point Processing2: – Image Histogram– FILTER

• Blur• Noise removal• Unsharp

– Pixelation