2. Point Processing

Image arithmetic defines as the implementation of standard arithmetic operations such as addition, subtraction, multiplication, and division on images or logical operations. This can be applied on one or more images. These operations are performed pixel by pixel which means the output image pixel values depends on the corresponding pixels in input image. Therefore, in order to perform these operation the image sizes should be kept same. Although image artimetic is most simple form of image processing, there is a wide range of applications. For example, image subtraction can be used for motion detection by detecting the differences between two or more frames of the same scene or image addition can be used to reduce random noise by adding successive images of the same scene. Logical operators in images are usually used with two or more images specifically binary images (black and white image). One of its application is masking the region of interest.

In this lab our tasks are the following.

  1. Addition of two images
  2. Difference between two images
  3. multiplication of image with scalar value

Image Addition

Image addition is performed on either one image by adding with a scale value or with two images pixel by pixel. Two identically sized images are added producing an output image with same size. Here we add two images by cv2.add() function or a simple numpy operation such as out = im1 + im2 can be used. Both the images should be of same size or the second image can just be a scalar value. Here we add two images such that the logo in second image is embedded into the first image. For simplicity puposes we have taken images with same size and are grayscale images.

import cv2

im1 = cv2.imread('ramaiah_building.png')
cv2.imshow("Image1", im1)

im2 = cv2.imread('ramaiah_logo.png')
cv2.imshow("Image2", im2)

im_out = cv2.add(im1, im2)
cv2.imshow("Added Image", im_out)
cv2.waitKey(0)
Addition of two images

Image subtraction

Image subtraction is performed on either one image subtracting with scalar value or with two images pixel by pixel. Similar to addition operation, two images of same size needs to be used to perform this operation. This concepts are used in many application one such is called background subtraction for counting or tracking the objects. In this task we take two images from the same camera in static position and placed at same angle. We perform change detection by using the concept of Absolute image differencing. Absolute difference is useful because as we know the image values cant be negative. For simplicity purposes, we have two images with same shape. Here the two images shows an image of a collection of screws and bolts. Both images look very similar and when we find difference we see there has been change detected. Change doesn’t mean just the objects in image it also could be light intensity and camera movement.

import cv2

im1 = cv2.imread('Picture1.png')
cv2.imshow("Image1", im1)

im2 = cv2.imread('Picture2.png')
cv2.imshow("Image2", im2)

im_out = abs(im1 - im2)
cv2.imshow("Difference Image", im_out)
cv2.waitKey(0)
Difference of two images

We see the output image is very noise with dots and shades. We learn more about cleaning up or filtering these noise in upcoming section.

Image multiplication

Like other arithmetic operations on images, image multiplication comes in two parts. One multiplying an image with scalar or multiplying with another image. The first concept is usually used for brightening or darkening an image and the second is mostly used as masking the region of interest. When there are two images needed to be multiplied we perfom pixel by pixel multiplication. Please note that Image multiplication can lead to larger values than maximum allowed pixel value, those values need to be truncated to the maximum value. In this task we take an image of robotic arm whose contrast is dark. If the scaling value is more than one it brightens the image and if it less than one it darkens the image. In our task we need to brighten the image.

import cv2

im = cv2.imread('robo_arm.png')
cv2.imshow("Original Image", im)

scale = 3
im_bright = im * scale
cv2.imshow("Brighten by scale 3", im_bright)
cv2.waitKey(0)

Multiplied by factor of 3

Image compliment

In order to find compliment of an image. We just need to subtract 255 from the original image. Try it on your own, the sample output is shown below:

Image Compliment

Here we see how whiter parts of images have gone darker and vise versa. Hence, they are sometimes called negative of an image.

Previous
Next