How do I change from 24 bit depth to 8 bit depth image?

17 views (last 30 days)
I have image data for my input 256x256x3 uint8 and the bit depth is 24. My question is, how can I change from 24 bit depth image to 8 bit depth image without changing the colortype in 'truecolor'? Here's my ans value. And here's my codes to read image and info image:-
>> I=imread('1234.png');
>> imfinfo('1234.png')

Accepted Answer

Walter Roberson
Walter Roberson on 27 Jun 2023
imread() im2uint8() imwrite()
  2 Comments
Dayangku Nur Faizah Pengiran Mohamad
Hello Sir. These codes didn't worked for me. It shown same bitdepth = 24
DGM
DGM on 10 Jul 2024
A truecolor image represented as 24b per pixel is 8b per sample (8b per sample, 3 samples per pixel). It will be read into the workspace as uint8, because that's how it's stored. It's already 8b data.
Since the stated goal is to produce an "8 bit" truecolor image, then that explicitly excludes indexed color representations.
I do not know of any image formats which support a conventional 8b per pixel RGB format (it might be possible with BMP, but good luck encoding/decoding it). There's good reason that such a thing might never be witnessed. At ~2b per sample, it would have terrible color resolution. This isn't 1989 anymore, so we're usually not interested in saving a few kB or accomodating legacy display buffers. Truecolor at 8bpp seems like an implausible interpretation.
So it's not indexed color, and it's probably not 8bpp RGB either. Therefore, we can conclude that indeed, the required image is the source image. How do you get an 8b image from your 24b image? You already have it.
However, there is one other possible interpretation if we discard the requirements and look at the actual usage. OP has a 24b truecolor representation of a grayscale medical image. They want an 8b image. If we disregard the assertion that the output should also be truecolor, then it would make sense that the "8bpp" representation can simply be obtained by collapsing the redundant RGB data into true single-channel grayscale. The answer then is to use im2gray(). The result would then be both 8b per pixel and 8b per sample.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!