You are on page 1of 4

Lab Manual # 4

“To Write and Execute Programs for Image Arithmetic Operations”


Objective:
• Addition of two images
• Subtract one image from another image
• Calculate mean value of image
• Different Brightness by changing mean value
Apparatus:
• PC/Laptop with Windows 7/8/8.1/10
• PyCharm Version: 2022.1.1
Theory:
I. Addition of Two Images:
We can add two images with the OpenCV function, cv.add().This directly adds up
image pixels in the two images.

Or simply by the numpy operation res = img1 + img2. Both images should
be of same depth and type, or the second image can just be a scalar value.

cv2.add(img1, img2)

Warning:

But adding the pixels is not an ideal situation. So, we use cv2.addweighted().
Remember, both images should be of equal size and depth.

Syntax:
cv2.addWeighted(img1, wt1, img2, wt2, gammaValue)

Parameters:

• img1:First Input Image array(Single-channel, 8-bit or floating-point)


• wt1:Weight of the first input image elements to be applied to the final image
• img2:Second Input Image array(Single-channel, 8-bit or floating-point)
• wt2:Weight of the second input image elements to be applied to the final image
• gammaValue:Measurement of light
Input Code:
i

Input Images:

image1 image2

OutPut:

Addition of Two Images

II. Subtraction of Two Images:


You can subtract two images by OpenCV function, cv.subtract(). res = img1 - img2.
Both images should be of same depth and type. Note that when used with RGBA images,
the alpha channel is also subtracted.

cv2.subtract(image1, image2)

Input Code:
Input Images:

Image 01 Image 02

Subtraction of Two Images

III. Calculate Mean Value of Image:


Mean value is the sum of pixel values divided by the total number of pixel values.

Pixel Values:

Each of the pixels that represents an image stored inside a computer has a pixel value
which describes how bright that pixel is, and/or what color it should be. In the simplest case
of binary images, the pixel value is a 1-bit number indicating either foreground or
background.Mean is most basic of all statistical measure.

Means are often used in geometry and analysis; a wide range of means have been
developed for these purposes. In contest of image processing filtering using mean is
classified as spatial filtering and used for noise reduction.This function is used to find the
mean value of each channel (RGB), there the output is three numbers.

ImageStat.Stat(Image)

Input Code:
Input Images:

OutPut:

Q1: What are arithmetic operations on two images?


Ans:
Arithmetic operations addition, subtraction, division, and multiplication which is. performed pixel
by pixel between two images or among many images. Addition operation. which is also called pixel
addition.

Q2: What are three primary types of image processing operations?


Ans:
The three primary types of image processing operations are:

• Spatial Domain Processing.


• Frequency Domain Processing
• Color Processing

Q3: Which operation is most suitable for image enhancement?


Ans: Here are some useful examples and methods of image enhancement:
• Filtering with morphological operators.
• Histogram equalization.
• Denoising.
• Linear contrast adjustment.

Conclusion:

You might also like