In this blog, we will learn how simple arithmetic operations like addition, subtraction etc can be used for image enhancement. First, let’s start with image addition also known as Image
Image Averaging
This is based on the assumption that noise present in the image is purely random(uncorrelated) and thus has zero average value. So, if we average n noisy images of
Applicability Conditions: Images should be taken under identical conditions with same camera settings like in the field of astronomy.
Advantages: Reduce noise without compromising image details unlike most other operations like filtering.
Disadvantages: Increases time and storage as now one needs to take multiple photos of the same object. Only applicable for random noise. Must follow the above applicability condition.
Below is the code where first I generated 20 images by adding random noise to the original image and then average these images to get the approx. original image.
cv2.randn(image, mean, standard deviation) fills the image with normally distributed random numbers with specified mean and standard deviation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import cv2 import numpy as np # Load original image img = cv2.imread('D:/downloads/forest.jpg') # Create list to store noisy images images = [] # Generate noisy images using cv2.randn. Can use your own mean and std. for _ in range(20): img1 = img.copy() cv2.randn(img1,(0,0,0),(50,50,50)) images.append(img+img1) # For averaging create an empty array, then add images to this array. img_avg=np.zeros((img.shape[0],img.shape[1],img.shape[2]),np.float32) for im in images: img_avg=img_avg+im/20 # Round the float values. Always specify the dtype img_avg=np.array(np.round(img_avg),dtype=np.uint8) # Display the images cv2.imshow('average_image',img_avg) cv2.imshow('original_image',img) cv2.imshow('noise_image',images[1]) cv2.waitKey(0) |
Image Subtraction
This is mainly used to enhance the difference between images. Used for background subtraction for detecting moving objects, in medical science for detecting blockage in the veins etc a field known as mask mode radiography. In this, we take 2 images, one before injecting a contrast medium and other after injecting. Then we subtract these 2 images to know how that medium propagated, is there any blockage or not.
Image Multiplication
This can be used to extract Region of interest (ROI) from an image. We simply create a mask and multiply the image with the mask to get the area of interest. Other applications can be shading correction which we will discuss in detail in the next blogs.
In the next blog, we will discuss intensity transformation, a spatial domain image enhancement technique. Hope you enjoy reading.
If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.