
How to Modify Intensity Level Resolution of Grayscale Image in MATLAB?
Intensity Level Resolution means number of pixels per square inches. The more the intensity resolution the more it provide a clear view. As well as the less the frame size is the more the image is clear. So, intensity level resolution is somehow related to the view frame. A image in mobile may seems clear than pc. Zooming in the image reduce intensity level resolution and zooming out increase intensity level resolution.
But modifying intensity level resolution is not zooming out or zooming in the image. Zooming is just perspective of view. To modify intensity level resolution you need to reduce number of bit in each pixel. That will use less bit for each pixel. And so, number of pixels per inches will be less than before.
Modifying Intensity Level Resolution in MATLAB
Here is a simple example of changing intensity level resolution in MATLAB. I have decreased the resolution in this program. If you want to increase the resolution you just need to multiply the image instead of dividing. See the code below:
ColorImage = imread('OriginalImage.jpg'); figure; imshow(ColorImage,'InitialMagnification','fit'); Grayscale = rgb2gray(ColorImage); figure; imshow(Grayscale,'InitialMagnification','fit'); [height, width] = size(Grayscale); Resizefactor = 0; figure; while Resizefactor<8 ReducedImage = Grayscale/2^Resizefactor; CurrentHighBit = 256/2^Resizefactor - 1; subplot(3,3,Resizefactor+1); imshow(ReducedImage, [0,CurrentHighBit]); title(256/2^Resizefactor); Resizefactor = Resizefactor + 1; end
Explanation of the Code
The above portion of this program has been explained in previous tutorial. So, in this tutorial I will explain the loop only.
while Resizefactor<8 ................ Resizefactor = Resizefactor + 1; end
This while loop will run from Resizefactor=0 to Resizefactor=7
. That means the loop will turn around 8 times. First time it will print the input image as Resizefactor=0
. Eight image generated in 8 steps will be printed to a 9×9 subplot.
ReducedImage = Grayscale/2^Resizefactor; CurrentHighBit = 256/2^Resizefactor - 1; subplot(3,3,Resizefactor+1); imshow(ReducedImage, [0,CurrentHighBit]); title(256/2^Resizefactor);
This is the most complex portion of this program. So, lets consider it from starting. At starting of loop the value of Resizefactor is 0.
So, 2Resizefactor = 1, which means Reduced Image is the Original Image.
As, our input image was in 256 gray level so the highest bit of the image was 255. Let’s find it from the loop.
There, 256/20 – 1 = 255
So, the intensity level (CurrentHighBit in Program) is same by loop and by input.
After that, we will increase the value of Resizefactor to 1.
So, 21 = 2, which means the image will be divided by 2.
As, previous gray level was 256, dividing by 2 we get 128 gray level so, highest bit will be 127 in this case.
If we form a table with Resize Factor, Intensity Level and Highest Bit that will look like below:
Refactor Size | Intensity Level | Highest Bit |
0 | 256 | 255 |
1 | 128 | 127 |
2 | 64 | 63 |
3 | 32 | 31 |
4 | 16 | 15 |
5 | 8 | 7 |
6 | 4 | 3 |
7 | 2 | 1 |
In case of Refactor Size = 7 the gray level is 2 and highest bit is 1. So, it is clear that the image bits are 0 and 1. Which means it is a black and white image.
According to the above table we can say that if we try to reduce intensity resolution one time the image will be converted to a binary or black and white image. If we try to reduce one more step then image data will be lost and whole thing will be just black. It is not possible to reduce than anymore.
Each case we will print the image from zero bit to highest bit. Which is specified by this parameter in imshow
function.
[0,CurrentHighBit]
If we run the code above we will get a output like this.

If you have any more problems please comment here.