Greetings, I am trying to find an easy way to manipulate an image so that I can decrease the quality of it from 8bit to 3bit.
What would be the easiest way to achieve this? Cheers
If you want to linearly scale it, just divide each pixel value by 255/7 (i.e. if the original image is stored in a matrix I, let the low-res image J = I/(255/7)).
UPDATED: Due to a mistake in my scaling constant.
Here's an example:

If you have an image that is stored as a uint8 type in MATLAB, then the pixel values will range from 0 to 255. To limit the values to only 3 bits of precision (thus using only the numbers 0 to 7), you can scale the data as in the following example:
>> data = uint8([0 23 128 200 255]); % Create some data of type uint8
>> scaledData = data*(7/255)
scaledData =
0 1 4 5 7
>> class(scaledData)
ans =
uint8
Note that even though the scaled values are limited to the range of 0 to 7, the variable storing them is still a uint8 data type since this is the smallest MATLAB will go. The unused higher bits are simply 0.
Depending on how you output the scaled image data to a file (if you want to do that), you may be able to reduce the precision of the stored values to less than 8 bits (for example, PNG files can store 4-bit types).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With