0% found this document useful (0 votes)
80 views

Lab 03 Arithematic and Logical Operations

Uploaded by

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

Lab 03 Arithematic and Logical Operations

Uploaded by

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

UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA

DEPARTMENT OF ELECTRICAL ENGINEERING

DIGITAL IMAGE PROCESSING LAB


Lab-03: Arithmetic & Logical Operations

LEARNING OUTCOME:
Understanding the importance and applications arithmetic and logical operations in digital image
processing.

INTRODUCTION:
Element-wise arithmetic operations between two images 𝑓(𝑥, 𝑦) and 𝑔(𝑥, 𝑦) are denoted as

𝑠(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) + 𝑔(𝑥, 𝑦)

𝑑(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) − 𝑔(𝑥, 𝑦)

𝑝(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) × 𝑔(𝑥, 𝑦)

𝑣(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) ÷ 𝑔(𝑥, 𝑦)

While performing the arithmetic operations, care should be taken not to exceed the maximum
allowable gray level value (dictated by the type of the image data class). Also, the negative values
need to be clipped to zero or scaled properly in the allowable range. Image values can be rescaled
between desired gray scale values using the following relation.

𝐼 − min⁡(𝐼)
𝐼𝑠𝑐𝑎𝑙𝑒𝑑 = 𝐾 × ( )
max(𝐼) − min⁡(𝐼)

where value of 𝐾 = 255 for 256 gray scale values. Arithmetic operations are used in number of
image applications, i.e., image enhancement, brightness adjustment, negative image generation,
region of interest extraction, etc.

LEARNING TASKS:
Download chapter 2 images of the Gonzalez DIP 3rd edition book from the link given below.
https://www.imageprocessingplace.com/DIP-3E/dip3e_book_images_downloads.htm
Import the libraries using the following commands
import os # Importing operating system library
import cv2 # Importing OpenCV library
import matplotlib.pyplot as plt # Importing Matploblib library
import numpy as np # Importing NumPy library

Working directory can be checked and changed using the following commands
print(os.getcwd()) # Checking default current working directory
new_cwd = os.chdir('complete path') # Changing/updating current working directory
print(os.getcwd()) # Should output new changed directory

Semester: Fall-2024 Instructor: Dr. Junaid Mir


Session: 2K21 Designed by: Dr. Junaid Mir
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING

 Image Subtraction:
1. Loss in an image resolution can also be identified through the image subtraction. In PYTHON,
read and display images Fig0220(a)(chronometer 3692x2812 2pt25 inch 1250 dpi).tif
a. Use the cv2.resize() command with the nearest neighbor interpolation function to
reduce the spatial resolution of the image by a factor of 3, 6 and 12. Then increase the
sizes of all three images using the nearest interpolation function to match the size of
the original image. Show the original image and resized images in a single 1 × 4 subplot
grid.
b. Calculate and view the difference between the original and the upscaled images from part-
a. Rescale the gray values in the difference images before visualizing the images. Show
the three difference images in a single 1 × 3 subplot grid. Where do you see the most
difference in an image?
c. Repeat part-a and part-b using the bicubic and bilinear interpolation schemes.

2. A commercially successful and highly beneficial use of image subtraction operation is in an


area of medical imaging called mask mode radiography. In PYTHON, read images
Fig0228(a)(angiography_mask_image).tif and Fig0228(b)(angiography_live_ image).tif
a. Display both images side by side with titles ‘Mask Image’ and ‘Live Image’. The mask
image is an original image whereas the live image is acquired once the X-ray contrast
medium is injected into the patient’s bloodstream after which x-ray image is taken. Can
you see the dye in the live image?
b. Compute the difference image by subtracting the live image from the mask image.
c. Show the mask image, live image, difference image without scaling and difference image
with proper scaling in a single 1 × 4 subplot grid. Can you see dye now?

 Image Division:
3. An important application of image division is shading correction. In PYTHON, read images
Fig0229(a)(tungsten_filament_shaded).tif and Fig0229(b)(tungsten_sensor_shading).tif.
a. Display both images side by side with titles ‘Shaded Image’ and ‘Shade Pattern’. An
imaging sensor has an associated shade pattern which is being multiplied with the image
during acquisition. As a result, the acquired image also has the similar shading pattern.
b. Perform shading correction by dividing the Shaded image with the shading pattern.
Rescale the gray values in the resulting image is needed.
c. Show the shaded, pattern and corrected images in a single 1 × 3 subplot grid. Can you
see the difference between the shaded image and the corrected image?

 Image Multiplication:

4. Image multiplication is also used in masking to extract region of interest (ROI). Read
Fig0230(a)(dental_xray).tif') and Fig0230(b)(dental_xray_mask).tif in PYTHON.
a. Display both images side by side with titles ‘Original Image’ and ‘Mask’. Which region
from the original image will be extracted if it is multiplied with mask image?
b. Multiply the mask image with the original image and display the resulting ROI after
scaling gray values properly.

Semester: Fall-2024 Instructor: Dr. Junaid Mir


Session: 2K21 Designed by: Dr. Junaid Mir
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING

 Bitwise LOGICAL Operations:

5. Image subtraction is used routinely for enhancing differences between images when they are
not visible with the naked eye. Read and view the Fig0227(a)(washington_infrared).tif image
in PYTHON.
a. We want to set the least significant bit of all image pixels to zero using bitwise AND
operator. What should be the values in the mask image with which you will perform the
bitwise AND operation to set LSB = 0 in your original image?
b. Perform bitwise AND operation by using cv2.bitwise_and() command. What will
be the result of this operation on your pixel intensities?
c. View the original and modified image by setting LSB to zero side by side. Can you see
any difference between the original and the modified image?
d. Display the original image, modified image and the difference image in a single 1 × 3
subplot grid.

6. Read Fig0230(a)(dental_xray).tif') and Fig0230(b)(dental_xray_mask).tif in PYTHON.


a. Extract ROI using an appropriate logical operation. Display the original, mask and ROI
images side by side with proper titles in a single 1 × 3 subplot grid.
b. Extract the non-ROI using appropriate logical operations. Display the original, mask and
non-ROI images side by side with proper titles in a single 1 × 3 subplot grid.

Semester: Fall-2024 Instructor: Dr. Junaid Mir


Session: 2K21 Designed by: Dr. Junaid Mir

You might also like