Download presentation
Presentation is loading. Please wait.
Published byDorcas Kelley Modified over 9 years ago
1
Basic Image Manipulation Raed S. Rasheed 2012
2
Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic and logical combination of images. – Addition and averaging. – Subtraction. – Division. – AND & OR. Transformation and Rotation
3
Region of Interest (ROI) A region of interest (ROI) is a rectangular area within the image, defined either by the coordinates of the pixels at its upper-left and lower-right corners or by the coordinates of its upper-left corner and its dimensions.
4
Basic Geometric Manipulation. Enlarging or shrinking an image can be accomplished by replicating or skipping pixels. These techniques can be used to magnify small details in an image, or reduce a large image in size so that it fits on the screen. They have the advantage of being fast, but can only resize an image by an integer factor.
5
Basic Geometric Manipulation. Enlarge: To enlarge an image by an integer factor n, we must replicate pixels such that each pixel in the input image becomes an n x n block of identical pixels in the output image. The most straightforward implementation of this involves iterating over the pixels in the larger output image and computing the coordinates of the input image pixel from which a value must be taken. For a pixel (x, y) in the output image, the corresponding pixel in the input image is at (x/n, y/n). Calculation of the coordinates is done using integer arithmetic.
6
Basic Geometric Manipulation.
8
Shrink: To shrink an image by an integer factor n, we must sample every n th pixel in the horizontal and vertical dimensions and ignore the others. Again, this technique is most easily implemented by iterating over pixels in the output image and computing the coordinates of the corresponding input image pixel.
9
Basic Geometric Manipulation.
11
Reflection: Reflection along either of the image axes can also be performed in place. This simply involves reversing the ordering of pixels in the rows or columns of the image.
12
Basic Geometric Manipulation.
14
Arithmetic and logical combination of images. Addition and averaging: I f we add two 8-bit greyscale images, then pixels in the resulting image can have values in the range 0 - 510. We should therefore choose a 16-bit representation for the output image or divide every pixel's value by two. If we do the latter, then we are computing an average of the two images. g(x,y) = αf 1 (x,y) + (1 - α)f 2 (x,y)
15
Arithmetic and logical combination of images. Addition and averaging: for(y=0; y<height; y++) for(x=0; x<width; x++) g(x,y) = αf 1 (x,y) + (1 - α)f 2 (x,y)
16
Arithmetic and logical combination of images. Subtraction: Subtracting two 8-bit greyscale images can produce values between -255 and +255. This necessitates the use of 16-bit signed integers in the output image unless sign is unimportant, in which case we can simply take the modulus of the result and store it using 8-bit integers: g(x,y) = |f 1 (x,y) - f 2 (x,y)|
17
Arithmetic and logical combination of images. Subtraction: for(y=0; y<height; y++) for(x=0; x<width; x++) g(x,y) = |f 1 (x,y) - f 2 (x,y)|
18
Arithmetic and logical combination of images. Subtraction:
19
Arithmetic and logical combination of images. Division: For division of images to produce meaningful results, floating-point arithmetic must be used. The ratio image can be of the floating-point type, or we can rescale and round pixel values to be in a more convenient 0-255 range.
20
Arithmetic and logical combination of images. Division: for(y=0; y<height; y++) for(x=0; x<width; x++) g(x,y) = f 1 (x,y) / f 2 (x,y)
21
Arithmetic and logical combination of images. Division:
22
Arithmetic and logical combination of images. AND & OR: Logical AND and OR operations are useful for the masking and compositing of images. For example, if we compute the AND of a binary image with some other image, then pixels for which the corresponding value in the binary image is 1 will be preserved, but pixels for which the corresponding binary value is 0 will be set to 0 themselves. Thus the binary image acts as a 'mask' that removes information from certain parts of the image.
23
Arithmetic and logical combination of images. AND & OR: for(y=0; y<height; y++) for(x=0; x<width; x++) g(x,y) = f 1 (x,y) && f 2 (x,y) for(y=0; y<height; y++) for(x=0; x<width; x++) g(x,y) = f 1 (x,y) || f 2 (x,y)
24
Arithmetic and logical combination of images. AND & OR:
25
Arithmetic and logical combination of images. AND & OR:
26
Transformation and Rotation
27
1.The pixel at (0, 100) after a 90° rotation 2.The pixel at (50, 0) after a 35° rotation In case 1, cos 90' is 0 and sin 90' is 1, so the pixel moves to coordinates (-100,0). This is clearly a problem, since pixels cannot have negative coordinates. Case 2 illustrates a different problem. Here, we calculate that x' = x cos θ - y sin θ = 50 cos(35 o ) = 40.96, y' = x sin θ + y cos θ = 50 sin(35 o ) = 28.68.
28
Transformation and Rotation The first problem can be solved by testing coordinates to check that they lie within the bounds of the output image before attempting to copy pixel values. A simple solution to the second problem is to find the nearest integers to x' and y' and use these as the coordinates of the transformed pixel.
29
Transformation and Rotation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.