How to reduce grayscale levels ?

13 ビュー (過去 30 日間)
Mohab Mostafa
Mohab Mostafa 2015 年 4 月 27 日
コメント済み: Image Analyst 2018 年 1 月 4 日
I have an RGB image, converted it into Grayscale image X = imread('lena.bmp'); Y = rgb2gray(X); now the image is represented by 8 bits (256 levels) and i want to quantize this image "Y" by reducing the grayscale levels to 32 (5 bits), how to do that ?
i know i can show the image like this imshow(Y,colormap(gray(32))); but that will just show the image with 32 levels and i want to save it in a variable not just showing it off

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 27 日
Use imquantize() or just divide the image by 8.
Y32 = Y / 8;
  10 件のコメント
soe
soe 2018 年 1 月 4 日
For image Y, to convert from 256 levels to 32 levels, the values should be 0 to 31. But Y/8 may be 0 to 32. (e.g. 255/8 = 31.875 becomes 32). So, how can i solve this problem?
Image Analyst
Image Analyst 2018 年 1 月 4 日
Use floor():
y8 = uint8(floor(double(y)/8))

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by