0% found this document useful (0 votes)
4 views35 pages

Chapter7 Basic Image Manipulation

Chapter 7 covers basic image manipulation techniques including defining a Region of Interest (ROI), geometric manipulations like enlargement, shrinking, and reflection, as well as arithmetic operations such as addition, subtraction, and logical combinations of images. It provides algorithms for these operations, detailing how to implement them in digital image processing. Additionally, it discusses transformations and rotations of images, including the necessary calculations for pixel repositioning.

Uploaded by

bakr khader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views35 pages

Chapter7 Basic Image Manipulation

Chapter 7 covers basic image manipulation techniques including defining a Region of Interest (ROI), geometric manipulations like enlargement, shrinking, and reflection, as well as arithmetic operations such as addition, subtraction, and logical combinations of images. It provides algorithms for these operations, detailing how to implement them in digital image processing. Additionally, it discusses transformations and rotations of images, including the necessary calculations for pixel repositioning.

Uploaded by

bakr khader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Chapter 7

Basic Image Manipulation


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

1
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.

Digital image processing a practical introduction using java, Nick Efford


2
Region of Interest (ROI)

Digital image processing a practical introduction using java, Nick Efford


3
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.
Digital image processing a practical introduction using java, Nick Efford
4
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.

Digital image processing a practical introduction using java, Nick Efford


5
Basic Geometric Manipulation.

ALGORITHM Image_Enlarge 3.1


01 INPUT Image, n
02 OUTPUT EnlargeImage
03 BEGIN
04 Create new image EnlargeImage; // with multiple size (n);
05 For each row in EnlargeImage
06 For each column in EnlargeImage
07 SET EnlargeImage(column,row) =
Image(column/n,row/n)
08 END For
09 END For
10 RETURN EnlargeImage;
11 END
Digital image processing a practical introduction using java, Nick Efford
6
Basic Geometric Manipulation.

Digital image processing a practical introduction using java, Nick Efford


7
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.

Digital image processing a practical introduction using java, Nick Efford


8
Basic Geometric Manipulation.

ALGORITHM Image_Shrink 3.2


01 INPUT Image, n
02 OUTPUT ShrinkImage
03 BEGIN
04 Create new image ShrinkImage; // with divided size (n)
05 For each row in ShrinkImage
06 For each column in ShrinkImage
07 SET ShrinkImage(column,row) = Image(column*n,
row*n);
08 END For
09 END For
10 RETURN ShrinkImage;
11 END
Digital image processing a practical introduction using java, Nick Efford
9
Basic Geometric Manipulation.

Digital image processing a practical introduction using java, Nick Efford


10
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.

Digital image processing a practical introduction using java, Nick Efford


11
Basic Geometric Manipulation.
ALGORITHM Image_Vertical_ Refliction 3.3
01 INPUT Image
02 OUTPUT ReflectionImage
03 BEGIN
04 Create new image ReflectionImage;
05 SET W = Image Width;
06 For each row in Image
07 For each column in Image
08 SET ReflectionImage(column,row) = Image(W – column –
1,row);
09 END For
10 END For
11 RETURN ReflectionImage;
12 END
Digital image processing a practical introduction using java, Nick Efford
12
Basic Geometric Manipulation.

Digital image processing a practical introduction using java, Nick Efford


13
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) = αf1(x,y) + (1 - α)f2(x,y)
Digital image processing a practical introduction using java, Nick Efford
14
Arithmetic and logical combination of images.

α = 0% α = 0%

α = 0% α = 0%

α = 0% α = 0%

α = 100% α = 0%

α = 50% α = 50%

α = 0% α = 100%

Digital image processing a practical introduction using java, Nick Efford


15
Arithmetic and logical combination of images.

ALGORITHM Image_Addition_Averaging 3.4


01 INPUT Image1, Image2, α
02 OUTPUT AddintionImage
03 BEGIN
04 Create new image AddintionImage;
06 For each row in Image1 and Image2
07 For each column in Image1 and Image2
08 SET AddintionImage(column,row) =
α * Image1(column,row) + ( 1 - α ) *
Image2(column,row);
09 END For
10 END For
11 RETURN AddintionImage;
12 END

Digital image processing a practical introduction using java, Nick Efford


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) = |f1(x,y) - f2(x,y)|
Digital image processing a practical introduction using java, Nick Efford
17
Arithmetic and logical combination of images.

ALGORITHM Image_Subtraction 3.5


01 INPUT Image1, Image2
02 OUTPUT SubtractionImage
03 BEGIN
04 Create new image SubtractionImage;
06 For each row in Image1 and Image2
07 For each column in Image1 and Image2
08 SET SubtractionImage(column,row) =
| Image1(column,row) - Image2(column,row) |;
09 END For
10 END For
11 RETURN SubtractionImage;
12 END

Digital image processing a practical introduction using java, Nick Efford


18
Arithmetic and logical combination of images.

Subtraction:

Digital image processing a practical introduction using java, Nick Efford


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.

ALGORITHM Image_Division 3.5


01 INPUT Image1, Image2
02 OUTPUT DivisionImage
03 BEGIN
04 Create new image DivisionImage;
06 For each row in Image1 and Image2
07 For each column in Image1 and Image2
08 SET DivisionImage(column,row) =
Rescale(Image1(column,row) / Image2(column,row));
09 END For
10 END For
11 RETURN DivisionImage;
12 END

Digital image processing a practical introduction using java, Nick Efford


21
Arithmetic and logical combination of images.

Division:

Digital image processing a practical introduction using java, Nick Efford


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.
Digital image processing a practical introduction using java, Nick Efford
23
Arithmetic and logical combination of images.

ALGORITHM Image_AND 3.6


01 INPUT Image1, Image2
02 OUTPUT ANDImage
03 BEGIN
04 Create new image ANDImage;
06 For each row in Image1 and Image2
07 For each column in Image1 and Image2
08 SET ANDImage(column,row) =
Image1(column,row) AND Image2(column,row);
09 END For
10 END For
11 RETURN ANDImage;
12 END

Digital image processing a practical introduction using java, Nick Efford


24
Arithmetic and logical combination of images.

ALGORITHM Image_OR 3.7


01 INPUT Image1, Image2
02 OUTPUT ORImage
03 BEGIN
04 Create new image ORImage;
06 For each row in Image1 and Image2
07 For each column in Image1 and Image2
08 SET ORImage(column,row) =
Image1(column,row) OR Image2(column,row);
09 END For
10 END For
11 RETURN ORImage;
12 END

Digital image processing a practical introduction using java, Nick Efford


25
Arithmetic and logical combination of images.

AND & OR:

Digital image processing a practical introduction using java, Nick Efford


26
Arithmetic and logical combination of images.

AND & OR:

Digital image processing a practical introduction using java, Nick Efford


27
Transformation and Rotation

Digital image processing a practical introduction using java, Nick Efford


28
Transformation
x\ = Tx(x,y)
y\ = Ty(x,y)

x\ = a0x+a1y+a2
y\ = b0x+b1y+b2

x\ a0 a1 a2
y\ =
b0 b1 b2

b2 b1 b0 a2 a1 a0 transformation
y 1 0 x 0 1 Translation by x,y
0 s 0 0 0 s Scaling by factor s
0 cos sin 0 -sin cos Clockwise rotation
0 1 0 0 s 1 Horizontal shear by a
factor s

Digital image processing a practical introduction using java, Nick Efford


29
Transformation
ALGORITHM Image_Transformation 3.8
01 INPUT Image, Tx ,Ty
02 OUTPUT TransformationImage
03 BEGIN
04 Create new image TransformationImage;
06 For each row in Image
07 For each column in Image
08 SET NewCol = column + Tx;
09 SET NewRow = row + Ty;
10 SET TransformationImage(NewCol,NewRow) =
Image(column,row);
11 END For
12 END For
13 RETURN TransformationImage;
14 END Digital image processing a practical introduction using java, Nick Efford
30
Transformation

Digital image processing a practical introduction using java, Nick Efford


31
Rotation
1. The pixel at (0, 100) after a 90° rotation
2. The pixel at (50, 0) after a 35° rotation

x' = x cos θ - y sin θ = 50 cos(35o ) = 40.96,


y' = x sin θ + y cos θ = 50 sin(35o ) = 28.68.

•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.


Digital image processing a practical introduction using java, Nick Efford
32
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.
Digital image processing a practical introduction using java, Nick Efford
33
Rotation
ALGORITHM Image_Rotation 3.9
01 INPUT Image, θ
02 OUTPUT RotationImage
03 BEGIN
04 Create new image RotationImage;
05 SET a0= Cos(θ), b0= Sin(θ), a1= - b0, b1= a0;
06 For each row in Image
07 For each column in Image
08 SET NewCol = Round(a0 * column + a1 * row);
09 SET NewRow = Round(b0 * column + b1 * row);
10 IF NewCol AND NewRow inside RotationImage THEN
11 SET RotationImage(NewCol,NewRow) = Image(column,row);
12 END IF
13 END For
14 END For
15 RETURN RotationImage;
Digital image processing a practical introduction using java, Nick Efford
16 END
34
Rotation

Digital image processing a practical introduction using java, Nick Efford


35

You might also like