arithmetic operations digitial image processing

Upload: rovick-tarife

Post on 10-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

Digital Image Processing using Arithmetic Operations

TRANSCRIPT

Paper Title (use style: paper title)

Image ArithmeticArithmetic Operations between Two Images using MATLAB Graphical User Interface (GUI)

Rovick P. TarifeEECE Department, College of EngineeringMindanao State University Iligan Institute of TechnologyIligan City, Lanao del Norte [email protected]

Abstract The basic concepts and application of arithmetic operations in digital image processing are presented in this paper. The process of different arithmetic operations between two images is also shown in detail. A graphical user interface (GUI) using MATLAB software was made to perform the different arithmetic methods. Index TermsImage addition, image subtraction, image multiplication, image divisionI. IntroductionImage arithmetic is the implementation of standard arithmetic operations, such as addition, subtraction, multiplication, and division on images. Image arithmetic has many uses in image processing both as a preliminary step in more complex operations and by itself. For example, image addition can be used to blend two or more images of the same scene or object.Using the MATLAB, arithmetic operations between two images can be performed. The Image Processing Toolbox software also includes a set of functions that implement arithmetic operations for all numeric, nonsparse data types. The toolbox arithmetic functions accept any numeric data type, including uint8, uint16, and double, and return the result image in the same format. The functions perform the operations in double precision, on an element-by-element basis, but do not convert images to double-precision values in the MATLAB workspace. Overflow is handled automatically.

II. Arithmetic OperatorsThere are four fundamental arithmetic operators in digital image processing. These operators are addition, subtraction, multiplication, and division.

A. Image Addition

In its most straightforward implementation, this operator takes as input two identically sized images and produces as output a third image of the same size as the first two, in which each pixel value is the sum of the values of the corresponding pixel from each of the two input images. More sophisticated versions allow more than two images to be combined with a single operation.A common variant of the operator simply allows a specified constant to be added to every pixel.The addition of two images is performed straightforwardly in a single pass. The output pixel values are given by:

R(i,j) = A(i,j) + B(i,j) (1)

Or if it is simply desired to add a constant value C to a single image then:

R(i,j) = A(i,j) + C (2)

If the pixel values in the input images are actually vectors rather than scalar values (e.g. for color images) then the individual components (e.g. red, blue and green components) are simply added separately to produce the output value.If the image format being used only supports, say 8-bit integer pixel values, then it is very easy for the result of the addition to be greater than the maximum allowed pixel value. The effect of this depends upon the particular implementation. The overflowing pixel values might just be set to the maximum allowed value, an effect known as saturation. Alternatively the pixel values might wrap around from zero again. If the image format supports pixel values with a much larger range, e.g. 32-bit integers or floating point numbers, then this problem does not occur so much.

B. Image Subtraction

The subtraction of two images is performed straightforwardly in a single pass. The output pixel values are given by:

R(i,j) = A(i,j) - B(i,j) (3)

Or if the operator computes absolute differences between the two input images then:

R(i,j) = |A(i,j) - B(i,j)| (4)

Or if it is simply desired to subtract a constant value C from a single image then:

R(i,j) = A(i,j) - C (5)

If the pixel values in the input images are actually vectors rather than scalar values (e.g. for color images) then the individual components (e.g. red, blue and green components) are simply subtracted separately to produce the output value.Implementations of the operator vary as to what they do if the output pixel values are negative. Some work with image formats that support negatively-valued pixels, in which case the negative values are fine (and the way in which they are displayed will be determined by the display colormap). If the image format does not support negative numbers then often such pixels are just set to zero (i.e. black typically). Alternatively, the operator may `wrap' negative values, so that for instance -30 appears in the output as 226 (assuming 8-bit pixel values).If the operator calculates absolute differences and the two input images use the same pixel value type, then it is impossible for the output pixel values to be outside the range that may be represented by the input pixel type and so this problem does not arise. This is one good reason for using absolute differences.

C. Image Multiplication

Like other image arithmetic operators, multiplication comes in two main forms. The first form takes two input images and produces an output image in which the pixel values are just those of the first image, multiplied by the values of the corresponding values in the second image. The second form takes a single input image and produces output in which each pixel value is multiplied by a specified constant. This latter form is probably the more widely used and is generally called scaling.This graylevel scaling should not be confused with geometric scaling.The multiplication of two images is performed in the obvious way in a single pass using the formula:

R(i,j) = A(i,j) B(i,j) (6)

Scaling by a constant is performed using:

R(i,j) = A(i,j) C (7)

Note that the constant is often a floating point number, and may be less than one, which will reduce the image intensities. It may even be negative if the image format supports that.

If the pixel values are actually vectors rather than scalar values (e.g. for color images) then the individual components (e.g. ref{rgb}{red, blue and green components}) are simply multiplied separately to produce the output value.If the output values are calculated to be larger than the maximum allowed pixel value, then they may either be truncated at that maximum value, or they can `wrap around' and continue upwards from the minimum allowed number again.

D. Image Division

The image division operator normally takes two images as input and produces a third whose pixel values are just the pixel values of the first image divided by the corresponding pixel values of the second image. Many implementations can also be used with just a single input image, in which case every pixel value in that image is divided by a specified constant.The division of two images is performed in the obvious way in a single pass using the formula:

R(i,j) = A(i,j) B(i,j) (8)

Division by a constant is performed using:

R(i,j) = A(i,j) C (9)

If the pixel values are actually vectors rather than scalar values (e.g. for color images) than the individual components (e.g. red, blue and green components) are simply divided separately to produce the output value.The division operator may only implement integer division, or it may also be able to handle floating point division. If only integer division is performed, then results are typically rounded down to the next lowest integer for output. The ability to use images with pixel value types other than simply 8-bit integers comes in very handy when doing division.

III. Arithmetic Operations GuiA graphical user interface (GUI) is a graphical display in one or more windows containing controls, called components that enable a user to perform interactive tasks. The user of the GUI does not have to create a script or type commands at the command line to accomplish the tasks. Unlike coding programs to accomplish tasks, the user of a GUI need not understand the details of how the tasks are performed.A graphical user interface was made to perform different arithmetic operations between two images. Figure 1 shows the overall design and display of the GUI.

Figure 1. Overall appearance of the GUI

The GUI is composed four axes and nine pushbuttons.The axes shown in Figure 1 are the following:

1. BACKGROUND displays the design background of the GUI2. IMAGE A displays the uploaded picture, Image A3. IMAGE B displays the uploaded picture, Image B4. RESULTING IMAGE displays the image result of performed arithmetic operation

The pushbuttons used in the GUI with their corresponding function are the following:

1. UPLOAD A uploads the picture, Image A to be used for arithmetic operation2. UPLOAD B uploads the picture, Image B to be used for arithmetic operation3. SHOW FULL SIZE pops up a MATLAB figure which displays the actual size of the image result4. RESET resets the GUI to default appearance5. ADD adds image A and B pixel by pixel6. SUBTRACT subtracts Image B from Image A pixel by pixel7. MULTIPLY multiplies Images A and B pixel by pixel8. DIVIDE divides Image A with Image B pixel by pixel9. AXC multiplies Image A with a constant value, C

The GUI utilizes functions from the Image Processing Toolbox of MATLAB. These are the functions used with their corresponding description:

1. imread read image from graphics file2. imshow display image3. imadd add two images or add constant to image4. imsubtract subtract one image from another or subtract constant from image5. immultiply multiply two images or multiply image by constant6. imdivide divide one image into another or divide image by constant

IV. Sample SimulationsDifferent arithmetic operations were performed using the designed GUI.A. Image Addition Simulation

The input images used for image addition were red.jpg and blue.jpg. The pictures both have a resolution of 500 x 500 pixels. red.jpg and blue.jpg are both plain colored image having the RGB values (255,0,0) and (0,0,255), respectively. Figure 2 shows the sample simulation.

Figure 2. Sample simulation of image addition

As shown in Figure 2, the output image is a magenta colored image having RGB value of (255,0,255). It also has a resolution of 500 x 500 pixels.

B. Image Subtraction Simulation

For image subtraction, yellow.jpg and green.jpg were used as input images. The pictures both have a resolution of 500 x 500 pixels. yellow.jpg and green.jpg are both plain colored image having the RGB values (255,255,0) and (0,255,0), respectively. Figure 3 shows the sample simulation.

Figure 3. Sample simulation of image addition

The output image of the simulation has also a resolution of 500 x 500 pixels. It is plain colored and has an RGB values of (255,0,0).

C. Image Multiplication Simulation

To simulate multiplication between two images, the pictures circlewithheart.jpg and check.jpg. Both images have a resolution of 500 x 500 pixels. Figure 4 shows the sample simulation of image multiplication.

Figure 4. Sample simulation of multiplication of two images

D. Image Division Simulation

For image division, circlewithheart.jpg and check.jpg were also used. Figure 5 shows the sample simulation of division of two images.

Figure 5. Sample simulation of divisionof two images

E. Scaling Simulation

To simulate scaling (multiplication of an image with a constant value), plant.jpg was used as an input. It is a grayscale picture of a plant having a resolution of 700 x 700 pixels. The value of constant, C used was 5. Figure 6 shows the result of the simulation.

Figure 6. Sample simulation of scaling

The result showed a brighter version of the input image. This is due to multiplying the value of each pixel by 5.

F. Error Messages

The GUI was designed to pop up different error messages when the user places wrong inputs. For example, when the user inputs images of different pixel sizes, an error message pops up as shown in Figure 7.

Figure 7. Error message stating inputs are of different pixel sizes

When the user inputs images of different types, an error message will pop up as shown in Figure 8.

Figure 8. Error message stating input images are of different types

The GUI also pops up an error message when input value of constant, C is not a number. The error message is shown in Figure 9

Figure 9. Error message stating the C input is not a number

V. ConclusionImage arithmetic applies one of the standard arithmetic operations or a logical operator to two or more images. The operators are applied in a pixel-by-pixel fashion which means that the value of a pixel in the output image depends only on the values of the corresponding pixels in the input images. Hence, the images normally have to be of the same size. One of the input images may be a constant value, for example when adding a constant offset to an image.MATLAB provides functions for image arithmetic that are easy to use. The GUI makes it easier for the user to perform the tasks and visualize the results. Although image arithmetic is the simplest form of image processing, there is a wide range of applications. A main advantage of arithmetic operators is that the process is very simple and therefore fast.

References[1] C. Solomon and T. Breckon, Fundamentals of Digital Image Processing: A Practical Approach with Examples in Matlab, 1st ed., John Wiley & Sons, Ltd, 2011, pp.5054.[2] R. Fisher, S. Perkins, A. Walker, and E. Wolfart (2003). Imaage Arithmetic [Online]. Available: http://homepages.inf.ed.ac.uk/rbf/HIPR2/arthops.htm[3] R. Gonzales and R. Woods Digital Image Processing, Addison Wesley, 1992, pp47-51, 185-187.