convert an 8 bit image into lower bits
Afficher commentaires plus anciens
Hi, I want to convert an 8bit gray scale image into lower bits. I have loaded the image and divided it by multiple numbers to downsize its number of bits, but the problem is that the result is not presenting the true form of White color, and the white color is removed with downsizing. Can you please tell me what is the correct method of downsizing the bits of an image. Regards

8 commentaires
Rik
le 5 Déc 2017
What is it you want? Downsizing an 8 bit image (256 colors) to 7 bits (128 colors)? I don't know why you would want that, but you can divide the data by 2 and round the result. If you have a double image, you can't do this.
The viewer bases the values for white and black on the data type and the values themselves. You need to provide alternative limits. (read the documentation to learn how to do that with the function you are using)
Badavath Purnesh Singh
le 12 Nov 2021
@Walter Roberson I have an 8 bit image, I would like to downsize it to 3 bit image. Can you help me do it ?
Walter Roberson
le 12 Nov 2021
Divide by 32.
Walter Roberson
le 12 Nov 2021
If you have an integer image that has N bits per pixel component, and you want to reduce it to M bits per pixel component, then divide by 2^(N-M) . 8 bits reduced to 3? Divide by 2^(8-3) = 2^5 = 32. 16 bits reduced to 10? Divide by 2^(16-10) = 2^6 = 64
Alicia Davion
le 9 Fév 2023
Hi @Walter Roberson i follow your 2^(N-M) to reduce 8bits image to 1bit image. So 1bit just have 2 level is black and white, but in my case, the 1bit have 3 level is black, gray, and white. The color range is [0 255] but if i devide it by 2^(8-1) = 128, the color range become [0 1 2] . Can you help me this case ? Ty
A 1 bit image cannot represent three different states. At any one location, a 1 bit image can have only 2^1 different states, 0 or 1. A 2 bit image can have 2^2 different states, binary 00 01 10 11 which are equivalent to decimal 0 1 2 3 . A 3 bit image can have 2^3 different states, binary 000 001 010 011 100 101 110 111 which are equivalent to decimal 0 1 2 3 4 5 6 7. This is the same way that a single-digit decimal number can have only 10^1 states, zero through nine, and a two-digit decimal number can have only 10^2 states, zero through ninety-nine.
If you need to represent 0 1 and 2 then you need a minimum of 2 bits per location. Though if you pack several locations together you can do better:
capacity3 = floor(log(2^32)/log(3))
so 32 bits can represent twenty base-3 digits instead of 32/2 = 16 digits if you did not pack the information densely.
If you are working with integer classes watch out for the fact that integer arithmetic rounds
IN = uint8(0:32:255)
IN/128
To prevent that you need to do something like
uint8(floor(double(IN)/128))
IN = uint8(0:32:255);
result = [IN; IN/128;
idivide(IN, 128, 'fix');
idivide(IN, 128, 'floor');
idivide(IN, 128, 'ceil');
idivide(IN, 128, 'round')]
Walter Roberson
le 9 Fév 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!