Kyoungju Park kjpark@cau.ac.kr http://graphics.cau.ac.kr Computer Graphics Kyoungju Park kjpark@cau.ac.kr http://graphics.cau.ac.kr
Image Processing 2D generalization of signal processing Image as a two-dimensional signal Point processing: modify pixels independently Filtering: modify based on neighborhood Compositing: combine several images Image compression: space-efficient formats Related topics (not in this lecture or this course) Image enhancement and restoration Computer vision
Outline Point Processing Filters Dithering Image Compositing Image Compression
Point Processing f(v) = v identity; no change f(v) = 1-v negate an image (black to white, white to black) f(v) = vp, p<1 brighten f(v) = vp, p>1 darken f(v) v Processing Examples -> Topics -> Image Processing->Brightness
PImage img; void setup() { size(200, 200); frameRate(30); img = loadImage("wires.jpg"); } void draw() { loadPixels(); for (int x = 0; x < img.width; x++) { for (int y = 0; y < img.height; y++ ) { int loc = x + y*img.width; float r = red (img.pixels[loc]); float maxdist = 50; float d = dist(x,y,mouseX,mouseY); float adjustbrightness = 255*(maxdist-d)/maxdist; r += adjustbrightness; color c = color(r); pixels[loc] = c; } updatePixels();
Convolution filters gaussian box tent
PImage img; int w = 80; float[][] matrix = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; void setup() { size(200, 200); frameRate(30); img = loadImage("end.jpg"); } void draw() { image(img,0,0); int matrixsize = 3; loadPixels(); for (int x = width/4; x < 3*width/4; x++) { for (int y = height/4; y < 3*height/4; y++ ) { color c = convolution(x,y,matrix,matrixsize,img); int loc = x + y*img.width; pixels[loc] = c; updatePixels();
color convolution(int x, int y, float[][] matrix,int matrixsize, PImage img) { float rtotal = 0.0; float gtotal = 0.0; float btotal = 0.0; int offset = matrixsize / 2; for (int i = 0; i < matrixsize; i++){ for (int j= 0; j < matrixsize; j++){ int loc = (x + i - offset) + img.width*(y + j - offset); rtotal += (red(img.pixels[loc]) * matrix[i][j]); gtotal += (green(img.pixels[loc]) * matrix[i][j]); btotal += (blue(img.pixels[loc]) * matrix[i][j]); } return color(rtotal,gtotal,btotal);
Blurring Filters A simple blurring effect can be achieved with a 3x3 filter centered around a pixel, More blurring is achieved with a wider nn filter: Original Image Blur 3x3 mask Blur 7x7 mask
Image Filtering: Blurring original, 64x64 pixels 3x3 blur 5x5 blur
Blurring Filters Average values of surrounding pixels Can be used for anti-aliasing What do we do at the edges and corners? For noise reduction, use median, not average Eliminates intensity spikes Non-linear filter Processing Examples -> Topics -> Image Processing->Blur
Example: Noise Reduction Image with noise Median filter (5x5)
Example: Noise Reduction Original image Image with noise Median filter (5x5)
Example of Edge Filter Original image Edge filter, then brightened
Image Filtering: Edge Detection
Dithering Dithering takes advantage of the human eye's tendency to "mix" two colors in close proximity to one another.
Dithering Dithering takes advantage of the human eye's tendency to "mix" two colors in close proximity to one another. original no dithering with dithering Colors = 224 Colors = 28 Colors = 28
Floyd-Steinberg Error Diffusion
Floyd-Steinberg Error Diffusion Enhances edges Retains high frequency Some checkerboarding From http://www.cs.rit.edu/~pga/pics2000/node1.html