basic image manipulation raed s. rasheed 2012. agenda region of interest (roi) basic geometric...

29
Basic Image Manipulation Raed S. Rasheed 2012

Upload: dorcas-kelley

Post on 31-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Image Manipulation

Raed S. Rasheed2012

Page 2: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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

Page 3: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 4: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 5: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 6: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 7: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 8: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Shrink:To shrink an image by an integer factor n, we must sample every nth 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.

Page 9: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 10: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 11: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

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.

Page 12: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 13: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Basic Geometric Manipulation.

Page 14: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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 range0 - 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) = αf1(x,y) + (1 - α)f2(x,y)

Page 15: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

Addition and averaging:

for(y=0; y<height; y++)

for(x=0; x<width; x++)

g(x,y) = αf1(x,y) + (1 - α)f2(x,y)

Page 16: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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) = |f1(x,y) - f2(x,y)|

Page 17: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

Subtraction:

for(y=0; y<height; y++)

for(x=0; x<width; x++)

g(x,y) = |f1(x,y) - f2(x,y)|

Page 18: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

Subtraction:

Page 19: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 20: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

Division:

for(y=0; y<height; y++)

for(x=0; x<width; x++)

g(x,y) = f1(x,y) / f2(x,y)

Page 21: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

Division:

Page 22: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 23: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

AND & OR:

for(y=0; y<height; y++)

for(x=0; x<width; x++)

g(x,y) = f1(x,y) && f2(x,y)

for(y=0; y<height; y++)

for(x=0; x<width; x++)

g(x,y) = f1(x,y) || f2(x,y)

Page 24: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

AND & OR:

Page 25: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Arithmetic and logical combination of images.

AND & OR:

Page 26: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Transformation and Rotation

Page 27: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Transformation and Rotation

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(35o ) = 40.96, y' = x sin θ + y cos θ = 50 sin(35o ) = 28.68.

Page 28: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

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.

Page 29: Basic Image Manipulation Raed S. Rasheed 2012. Agenda Region of Interest (ROI) Basic geometric manipulation. – Enlarge – shrink – Reflection Arithmetic

Transformation and Rotation