Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Images and 2D Graphics COMP 112 2014 # 17.

Similar presentations


Presentation on theme: "School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Images and 2D Graphics COMP 112 2014 # 17."— Presentation transcript:

1 School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Images and 2D Graphics COMP 112 2014 # 17

2 COMP112 17: 2 Menu Graphics Images and image manipulation Admin Test: 15 th April, 4-5pm, A – L: HMLT104, M – Z: HULT323

3 COMP112 17: 3 Image manipulation What kinds of manipulation are there? Independent pixels: changing colors: (brightness, contrast, redness,…..) Geometric transformations translate, rotate, reflect, skew, scale/resize parts of images may involve interpolation to find new pixel values Selecting and modifying regions spread fill representing non-rectangular regions Applying “filters” blur, sharpen, ….. Image recognition.

4 COMP112 17: 4 Geometric Transforms If you translate, rotate, scale, etc the pixels may not line up: pixel (3,1)  pixel (2.7, 2.2) pixel (1,4)  pixel (1.3, 2.8) What value do you use for the new pixels? Options: use truncated pixel coordinates use rounded pixel coordinates take average of overlapping pixels interpolate overlapping pixels (average weighted by distance or degree of overlap)

5 COMP112 17: 5 Geometric Transforms If you translate, rotate, scale, etc the pixels may not line up: pixel (3,1)  pixel (2.7, 2.2) pixel (1,4)  pixel (1.3, 2.8) What about pixels over the edge? What about missing pixel values? Options: drop pixels outside change dimensions of image blank missing pixels (white/black/grey….) use original pixel values.

6 COMP112 17: 6 Computing new pixel value Truncate/Round coordinates: To compute new pixel value at (i, j) work out the pixel that it came from (eg if translate by dx and dy, came from (i-dx, j-dy)) round/truncate to integers. oi = (int) (i-dx); oj = (int) (j-dy); check coords are within image (oi>= 0 && oi<=width, …) use pixel value at those cords of original image. How do you make sure that the new values don’t mess up the old values during the calculation? Always have two image arrays: original image new image. Construct values in new image from values in old image Then copy over. Easier doing reverse direction than forward direction

7 COMP112 17: 7 Transforming int [ ][ ][ ] newImage = new int [image.length] [image[0].length] [3]; for (int i = 0; i< newImage.length; i++){ for (int j = 0; j< newImage.length; j++){ int oi = (int)(i - translateX)); // or whatever transformation int oj = (int)(i - translateY); if (oi>=0 && oi = 0 && ok <= image[0].length) { newImage[ i ][ j ] = image[oi][oj]; // not safe!! newImage[ i ][ j ] = Arrays.copyOf(image[oi][oj], 3); } else { newImage [ i ][ j ] = = new int[ ]{ 0, 0,0}; } image = newImage;

8 COMP112 17: 8 Rotation How can we rotate image by  degrees? Must specify the center of rotation: xCenter, yCenter Need trigonometry: forward xNew = xCenter + (x-xCenter) cos(  ) – (y-yCenter) sin(  ) yNew = yCenter + (x-xCenter) sin(  ) + (y-yCenter) cos(  ) reverse x = xCenter + (xNew-xCenter) cos(  ) + (yNew-yCenter) sin(  ) y = yCenter - (xNew-xCenter) sin(  ) + (yNew-yCenter) cos(  ) x,y xNew, yNew  xCenter,yCenter

9 COMP112 17: 9 Interpolating double ox = (….i ….. j…); double oy = (…. i …..j…); int oi = (int) ox; double oy = (int) oy; newImage[ i ][ j ] = image[oi][oj] * (1-Math.hypot(ox-oi, oy-oj) + image[oi+1][oj] * + image[oi][oj+1] * + image[oi+1][oj+1] * +

10 COMP112 17: 10 Blur, Filters, Convolution Many image transformations involve replacing each pixel with some function of the pixel values in its neighbourhood: Blur, changing resolution: pixel → average of neighbourhood Sharpening, edge detection pixel → "difference" between pixel and neighbours

11 COMP112 17: 11 Blur, Filters, Convolution Many image transformations involve replacing each pixel with some function of the pixel values in its neighbourhood: Blur, changing resolution: pixel → average of neighbourhood Sharpening, edge detection pixel → "difference" between pixel and neighbours Convolution: Apply "neighbour weights" to each pixel in image: 0.050.10.05 0.10.40.1 0.050.10.05

12 COMP112 17: 12 Convolution Filtering input: image: rows x cols array of pixel filter:height x width array of weights, usually height & width are odd, and weights sum to 1.0 output: newImage: rows x cols array of pixel for row ← 0.. rows-1 for col ← 0.. cols-1 ht2 ← (height-1)/2, wd2 ← (width-1)/2 for r ← –ht2.. ht2 for c ← –wd2.. wd2 newImage[row, col] += image[row+r][col+c] * filter[r+ht2] [c+w2] Problems: Have to take care at the edges How do you multiply colours? 0.050.10.05 0.1 0.4 0.1 0.050.10.05

13 COMP112 17: 13 Filters Blur: what are good weights? Gaussian distribution (weight = gaussian of distance from center) 0.050.10.05 0.10.40.1 0.050.10.05.006.011.022.0110.050.1.0220.10.2.011 0.05 0.1.006.011.022.0110.050.10.05.011.006.011.022.011.006 0.0000 0067 0.0000 2292 0.0001 9117 0.0003 8771 0.0001 9117 0.0000 2292 0.0000 0067 0.0000 2292 0.0007 8633 0.0065 5965 0.0133 0373 0.0065 5965 0.0007 8633 0.0000 2292 0.0001 9117 0.0065 5965 0.0547 2157 0.1109 8164 0.0547 2157 0.0065 5965 0.0001 9117 0.0003 8771 0.0133 0373 0.1109 8164 0.2250 8352 0.1109 8164 0.0133 0373 0.0003 8771 0.0001 9117 0.0065 5965 0.0547 2157 0.1109 8164 0.0547 2157 0.0065 5965 0.0001 9117 0.0000 2292 0.0007 8633 0.0065 5965 0.0133 0373 0.0065 5965 0.0007 8633 0.0000 2292 0.0000 0067 0.0000 2292 0.0001 9117 0.0003 8771 0.0001 9117 0.0000 2292 0.0000 0067

14 COMP112 17: 14 Filters "Bokeh" or lens blur effect of an out-of-focus lens convolve with a uniform circular filter 00 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

15 COMP112 17: 15 Sharpening Emphasise pixels that are very different from their neighbours "unsharpening" = original – blurred image has –ve weights ⇒ must be careful not to make invalid pixel values "Real" sharpening: This is symmetric; how does it sharpen an edge? 0-0.10 1.4-0.1 0 0 -.05-0.1-.05 -0.11.6-0.1 -.05-0.1-.05 0.050.10.05 0.10.40.1 0.050.10.05 000 010 000 -.03-.05-.03 -.050.8-.5 -.03-.05-.03 – 0.5 x ⇒

16 COMP112 17: 16 Sharpening an edge. 111111098765 0-0.10 1.4-0.1 0 0 11111109876511111 9876511111 9876511111 9876511111 9876511111 98765

17 COMP112 17: 17 Edge Detection Simple: (D of G) sum to 0 ⇒ constant areas → 0 only "edge" regions bright Complex: Requires more than just a convolution filter eg Canny: convolution, gradients, threshold, … -.1-.2-.1 -.22.24-.2 -.1-.2-.1 -.07 -.1 -.07 -.1 -.07 -.1-.07-.02 -.07-.1-.07-.02


Download ppt "School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Images and 2D Graphics COMP 112 2014 # 17."

Similar presentations


Ads by Google