Image Normalization: From 2-bit to 8-bit
Introduction:
Image normalization, which helps to modify an image’s contrast and brightness to make it more visually appealing or appropriate for analysis, is a crucial method in digital image processing. Image normalization is frequently used to transform low-bit images, like 2-bit images, into higher-bit images, such as 8-bit images.
Mathmetically:
I_N=round{(I(i,j)-min(i,j)\max(i,j)-min(i,j))*255}
Where I_N is normalized image, I(i,j) is current pixel,
max_(i,j) is pixel with maximum intensity value in image,
min_(i,j) is pixel with minimum intensity value and
255 is maximum intensity value of 8-bit image since goal is to normalize input image to 8-bit.
This value can be different depending upon the requirement i.e. for 7-bit normalization it will be 128 and so on.
This blog post will look at a code snippet that accomplishes this kind of normalization and go into detail about how it functions.
Code Explanation: Here is the code that performs the normalization of an image from 2-bit to 8-bit by scaling the pixel values to the range of 0 to 255:
original_img=double(original_img);
normalized_img=zeros(size(original_img));
min_val = min(original_img(:));
max_val = max(original_img(:));
normalized_img = round (((original_img — min_val) / (max_val — min_val))*255);
normalized_img = uint8(normalized_img);
The double function is used to first change the input picture, original img, from an integer format to a floating-point one. To ensure that the pixel values may be stretched to a greater range, this is required.
The program then constructs a label array called normalized img, which is identical in size to the input image but contains only zeros. The values of the normalized pixels will be kept in this array.
The third and fourth lines of the code, respectively, determine the input image’s lowest and maximum pixel values. The code is made more effective by using the min and max functions on the flattened array that original img(:) returns.
The real normalization is done in a single line of code on the fifth line. The code scales the pixel values to the range of 0 to 255 by subtracting the minimum pixel value (min val) from the original pixel values and multiplying the result by the scaling factor (255 / (max val — min val)). After that, the values are kept in the proper location in the normalized img array.
The normalized pixel values are again converted to unsigned 8-bit integer format using the uint8 function in the last line of the program. Most image processing operations require pixel values to be in this format, hence this is necessary.
Conclusion:
The essential method of image normalization in digital image processing helps to improve the contrast and brightness of images. In this blog post, we looked at a code snippet that converts a 2-bit image to an 8-bit image. Understanding the code and how it functions will allow you to use comparable methods for your own image processing projects.