Graphics Image Processing kucg korea ac kr Graphics

  • Slides: 70
Download presentation
Graphics Image Processing 고려대학교 컴퓨터 그래픽스 연구실 kucg. korea. ac. kr Graphics Lab @

Graphics Image Processing 고려대학교 컴퓨터 그래픽스 연구실 kucg. korea. ac. kr Graphics Lab @ Korea University

Overview n Image Representation n n KUCG What is an image? Sampling and Reconstruction

Overview n Image Representation n n KUCG What is an image? Sampling and Reconstruction n Key steps in image processing kucg. korea. ac. kr Graphics Lab @ Korea University

What is an Image? n KUCG An image is a 2 D rectilinear array

What is an Image? n KUCG An image is a 2 D rectilinear array of pixels Continuous image Digital image A pixel is a sample, not a little square!! kucg. korea. ac. kr Graphics Lab @ Korea University

What is an Image? n KUCG An image is a 2 D rectilinear array

What is an Image? n KUCG An image is a 2 D rectilinear array of pixels Continuous image kucg. korea. ac. kr Digital image Graphics Lab @ Korea University

What is an Image? n KUCG An image is a 2 D rectilinear array

What is an Image? n KUCG An image is a 2 D rectilinear array of pixels Continuous image kucg. korea. ac. kr Digital image Graphics Lab @ Korea University

Image Acquisition n KUCG Pixels are samples from continuous function Photoreceptors in eye n

Image Acquisition n KUCG Pixels are samples from continuous function Photoreceptors in eye n CCD cells in digital camera n Rays in virtual camera n kucg. korea. ac. kr Graphics Lab @ Korea University

Quantization n KUCG Artifact due to limited intensity resolution Frame buffers have limited number

Quantization n KUCG Artifact due to limited intensity resolution Frame buffers have limited number of bits per pixel n Physical devices have limited dynamic range n 255 150 255 255 150 150 75 750 255 150 75 750 255 150 75 0 kucg. korea. ac. kr 75 750 0 0 Blue channel Green channel Red channel Graphics Lab @ Korea University

Image Display n KUCG Re-create continuous function from samples n Example: cathode ray tube

Image Display n KUCG Re-create continuous function from samples n Example: cathode ray tube Image is reconstructed by displaying pixels with finite area (Gaussian) kucg. korea. ac. kr Graphics Lab @ Korea University

Image Resolution n Intensity resolution n n Each pixel has only “Depth” bits for

Image Resolution n Intensity resolution n n Each pixel has only “Depth” bits for colors/intensities Spatial resolution n n KUCG Image has only “Width” x “Height” pixels Temporal resolution n Monitor refreshes images at only “Rate” Hz kucg. korea. ac. kr Graphics Lab @ Korea University

Overview n Image Representation n n KUCG What is an image? Sampling and Reconstruction

Overview n Image Representation n n KUCG What is an image? Sampling and Reconstruction n Key steps in image processing kucg. korea. ac. kr Graphics Lab @ Korea University

Sampling and Reconstruction KUCG Sampling Reconstruction kucg. korea. ac. kr Graphics Lab @ Korea

Sampling and Reconstruction KUCG Sampling Reconstruction kucg. korea. ac. kr Graphics Lab @ Korea University

Sampling and Reconstruction kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Sampling and Reconstruction kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add luminance n Add contrast n n Warping Scale n Rotate n Warps n kucg. korea. ac. kr Graphics Lab @ Korea University

Adjusting Brightness n KUCG Simply scale pixel components n Must clamp to range (e.

Adjusting Brightness n KUCG Simply scale pixel components n Must clamp to range (e. g. , 0 to 255) Original kucg. korea. ac. kr Brighter Graphics Lab @ Korea University

Adjusting Contrast n Compute mean luminance L for all pixels n n KUCG Luminance

Adjusting Contrast n Compute mean luminance L for all pixels n n KUCG Luminance = 0. 30*r + 0. 59*g + 0. 11*b Scale deviation from L for each pixel component n Must clamp to range (e. g. 0 to 255) L Original kucg. korea. ac. kr More contrast Graphics Lab @ Korea University

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add luminance n Add contrast n n Warping Scale n Rotate n Warps n kucg. korea. ac. kr Graphics Lab @ Korea University

Adjusting Blurriness n KUCG Convolve with a filter whose entries sum to one n

Adjusting Blurriness n KUCG Convolve with a filter whose entries sum to one n Each pixel becomes a weighted average of its neighbors Original kucg. korea. ac. kr Blur Graphics Lab @ Korea University

Edge Detection n KUCG Convolve with a filter that finds differences between neighbor pixels

Edge Detection n KUCG Convolve with a filter that finds differences between neighbor pixels Original kucg. korea. ac. kr Edge Detection Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 We call this “filter” kucg. korea. ac. kr Graphics

Blurring and Convolution KUCG 3 We call this “filter” kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Blurring and Convolution KUCG 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Edge Detection kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Edge Detection kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Discretize Convolution kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Discretize Convolution kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Edge Detection n Pixel alteration using convolution mask KUCG int sum. X, sum. Y,

Edge Detection n Pixel alteration using convolution mask KUCG int sum. X, sum. Y, sum; for( y=1 ; y<image_height-1 ; y++ ) for( x=1 ; x<image_width-1 ; x++ ) { sum. X=0; for( j=0 ; j<3 ; j++ ) for( i=0 ; i<3 ; i++ ){ sum. X += mask. X[i][j]*image[x+i-1][y+j-1] } sum. Y=0; for( j=0 ; j<3 ; j++ ) for( i=0 ; i<3 ; i++ ){ sum. Y += mask. Y[i][j]*image[x+i-1][y+j-1] } mask sum = abs(sum. X)+abs(sum. Y); if(sum > 255) sum =255; if(sum < 0) sum = 0; result_Image[x][y] = sum; } kucg. korea. ac. kr Graphics Lab @ Korea University

Edge Detection n KUCG Various masks for edge detection Prewitt Sobel Frei-Chen Laplacian 1

Edge Detection n KUCG Various masks for edge detection Prewitt Sobel Frei-Chen Laplacian 1 Laplacian 2 Laplacian 3 kucg. korea. ac. kr Graphics Lab @ Korea University

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add

Image Processing § Pixel operations KUCG n Filtering Blur n Detect edge n Add luminance n Add contrast n n Warping Scale n Rotate n Warps n kucg. korea. ac. kr Graphics Lab @ Korea University

Image Warping n KUCG Move pixels of image Mapping n Resampling n Warp Source

Image Warping n KUCG Move pixels of image Mapping n Resampling n Warp Source Image kucg. korea. ac. kr Destination Image Graphics Lab @ Korea University

Overview n KUCG Mapping Forward n Reverse n n Resampling Point sampling n Triangle

Overview n KUCG Mapping Forward n Reverse n n Resampling Point sampling n Triangle filter n Gaussian filter n kucg. korea. ac. kr Graphics Lab @ Korea University

Mapping n KUCG Define transformation n Describe the destination (x, y) for every location

Mapping n KUCG Define transformation n Describe the destination (x, y) for every location (u, v) in the source (or vice-versa, if invertible) v y u kucg. korea. ac. kr x Graphics Lab @ Korea University

Example Mappings n KUCG Scale by factor : x = factor * u n

Example Mappings n KUCG Scale by factor : x = factor * u n y = factor * v n v y Scale 0. 8 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Example Mappings n KUCG Rotate by θ degrees: x = u cos θ –

Example Mappings n KUCG Rotate by θ degrees: x = u cos θ – v sin θ n y = u sin θ + v cos θ n y v Rotate 30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Example Mappings n Shear in X by factor : x = u + factor

Example Mappings n Shear in X by factor : x = u + factor * v ny=v n n KUCG v Shear X 1. 3 Shear in Y by factor : x=u n y = v + factor * u n y u v y Shear Y 1. 3 u kucg. korea. ac. kr x x Graphics Lab @ Korea University

Other Mappings n KUCG Any function of u and v : x = fx(u,

Other Mappings n KUCG Any function of u and v : x = fx(u, v) n y = fy(u, v) n Fish-eye kucg. korea. ac. kr Swirl Rain Graphics Lab @ Korea University

Image Warping Implementation I n KUCG Forward mapping : for(int u=0; u<umax; u++) {

Image Warping Implementation I n KUCG Forward mapping : for(int u=0; u<umax; u++) { for(int v=0; v<vmax; v++) { float x = fx(u, v); float y = fy(u, v); dst(x, y) = src(u, v); } } (u, v) Source Image kucg. korea. ac. kr f (x, y) Destination Image Graphics Lab @ Korea University

Forwarding Mapping n KUCG Iterate over source image y v Rotate -30 u kucg.

Forwarding Mapping n KUCG Iterate over source image y v Rotate -30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Forwarding Mapping – NOT n KUCG Iterate over source image Many source pixels can

Forwarding Mapping – NOT n KUCG Iterate over source image Many source pixels can map to same destination pixel y v Rotate -30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Forwarding Mapping – NOT n Iterate over source image Many source pixels can map

Forwarding Mapping – NOT n Iterate over source image Many source pixels can map to same destination pixel KUCG Some destination pixels may not be covered y v Rotate -30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Image Warping Implementation II n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int

Image Warping Implementation II n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = fx-1(x, y); float v = fy-1(x, y); dst(x, y) = src(u, v); } } (u, v) Source Image kucg. korea. ac. kr f (x, y) Destination Image Graphics Lab @ Korea University

Reverse Mapping n KUCG Iterate over destination image At least, no pixel in destination

Reverse Mapping n KUCG Iterate over destination image At least, no pixel in destination goes empty n Must resample source n May oversample, but much simpler n y v Rotate -30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Resampling n KUCG Evaluate source image at arbitrary (u, v) Usually (u, v) is

Resampling n KUCG Evaluate source image at arbitrary (u, v) Usually (u, v) is not an integer (u, v) Source Image kucg. korea. ac. kr (x, y) Destination Image Graphics Lab @ Korea University

Overview n KUCG Mapping Forward n Reverse n n Resampling Point sampling n Triangle

Overview n KUCG Mapping Forward n Reverse n n Resampling Point sampling n Triangle filter n Gaussian filter n kucg. korea. ac. kr Graphics Lab @ Korea University

Point Sampling n KUCG Take value at closest pixel n int iu = trunc(u+0.

Point Sampling n KUCG Take value at closest pixel n int iu = trunc(u+0. 5); int iv = trunc(v+0. 5); dst(x, y) = src(iu, iv); This method is simple, but it causes aliasing y v F u kucg. korea. ac. kr x Graphics Lab @ Korea University

Triangle Filtering n KUCG Convolve with triangle filter Input kucg. korea. ac. kr Output

Triangle Filtering n KUCG Convolve with triangle filter Input kucg. korea. ac. kr Output Graphics Lab @ Korea University

Triangle Filtering n KUCG Bilinearly interpolate four closest pixels a = linear interpolation of

Triangle Filtering n KUCG Bilinearly interpolate four closest pixels a = linear interpolation of src(u 1, v 2) and src(u 2, v 2) n b = linear interpolation of src(u 1, v 1) and src(u 2, v 1) n dst(x, y) = linear interpolation of “a” and “b” n a (u 1, v 2) (u 2, v 2) (u, v) (u 1, v 1) (u 2, v 1) b kucg. korea. ac. kr Graphics Lab @ Korea University

Gaussian Filtering n KUCG Convolve with Gaussian filter Input Output Width of Gaussian kernel

Gaussian Filtering n KUCG Convolve with Gaussian filter Input Output Width of Gaussian kernel affects bluriness kucg. korea. ac. kr Graphics Lab @ Korea University

Gaussian Filtering n KUCG Compute weighted sum of pixel neighborhood : n Weights are

Gaussian Filtering n KUCG Compute weighted sum of pixel neighborhood : n Weights are normalized values of Gaussian function r (u, v) kucg. korea. ac. kr Graphics Lab @ Korea University

Filtering Methods Comparison n KUCG Trade-offs Aliasing versus blurring n Computation speed n Point

Filtering Methods Comparison n KUCG Trade-offs Aliasing versus blurring n Computation speed n Point kucg. korea. ac. kr Bilinear Gaussian Graphics Lab @ Korea University

Image Warping Implementation III n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int

Image Warping Implementation III n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = fx-1(x, y); float v = fy-1(x, y); dst(x, y) = resample_src(u, v, w); } } (u, v) f Source Image kucg. korea. ac. kr (x, y) Destination Image Graphics Lab @ Korea University

Image Warping Implementation III n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int

Image Warping Implementation III n KUCG Reverse mapping for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = fx-1(x, y); float v = fy-1(x, y); dst(x, y) = resample_src(u, v, w); } } (u, v) f w Source Image kucg. korea. ac. kr (x, y) Destination Image Graphics Lab @ Korea University

Example: Scale n KUCG Scale (src, dst, sx, sy) : float w ≈ max(1/sx,

Example: Scale n KUCG Scale (src, dst, sx, sy) : float w ≈ max(1/sx, 1/sy) for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = x/sx ; float v = y/sy; dst(x, y) = resample_src(u, v, w); } v y } (u, v) Scale 0. 5 (x, y) u kucg. korea. ac. kr x Graphics Lab @ Korea University

Example: Rotate n KUCG Rotate (src, dst, theta) for(int x=0; x<xmax; x++) { for(int

Example: Rotate n KUCG Rotate (src, dst, theta) for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = x*cos(-θ)-y*sin(-θ) float v = x*sin(-θ)+y*cos(-θ) dst(x, y) = resample_src(u, v, w); } y v } (x, y) (u, v) Rotate 30 u kucg. korea. ac. kr x Graphics Lab @ Korea University

Example: Fun n KUCG Swirl (src, dst, theta) for(int x=0; x<xmax; x++) { for(int

Example: Fun n KUCG Swirl (src, dst, theta) for(int x=0; x<xmax; x++) { for(int y=0; y<ymax; y++) { float u = rot(dist(x, xcenter)*θ) float v = rot(dist(y, ycenter)*θ) dst(x, y) = resample_src(u, v, w); } v } (u, v) y (x, y) Swirl 45 u kucg. korea. ac. kr x Graphics Lab @ Korea University