フィルターのクリア

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

11 ビュー (過去 30 日間)
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad 2023 年 6 月 27 日
コメント済み: DGM 2024 年 7 月 10 日 6:06
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')

採用された回答

Walter Roberson
Walter Roberson 2023 年 6 月 27 日
imread() im2uint8() imwrite()
  2 件のコメント
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad 2023 年 6 月 27 日
Hello Sir. These codes didn't worked for me. It shown same bitdepth = 24
DGM
DGM 2024 年 7 月 10 日 6:06
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by