How to reduce the bit depth of the bmp image from 8-bit to n-bit, where n<8 andn>=1. Choose n=3.
23 ビュー (過去 30 日間)
古いコメントを表示
-bit depth reduction -what function to be used
4 件のコメント
Mayan Rumbak
2020 年 11 月 3 日
I need something similar...
I have a 4-bit depth BMP that I would like to read - manipulate - and save back as BMP with 4-bit depth.
but I don't know how to do it...
Does anyone have an idea?
Image Analyst
2020 年 11 月 3 日
Yes:
rgbImage = imread(filename); % Read in.
% Code to manipulate - whatever that means.
% Make 4 bit
if max(rgbImage(:)) > 15 % If it's more than 4 bits now, rescale
rgbImage = rescale(rgbImage, [0, 15]);
end
% Save back out.
imwrite(outputFileName, uint8(rgbImage));
回答 (1 件)
Image Analyst
2015 年 3 月 28 日
Just divide the image by a power of 2. For example to convert an 8 bit image to another, lower bits image:
image7bit = image8bit / 2;
image6bit = image8bit / 4;
image5bit = image8bit / 8;
image4bit = image8bit / 16;
image3bit = image8bit / 32;
image2bit = image8bit / 64;
image1bit = image8bit / 128;
1 件のコメント
Image Analyst
2015 年 3 月 28 日
sunnie, this does not change the number of bits to n. It changes the number of colors to n. The resulting image is an indexed image - an array where the values go from 1 to n. The image is an 8 bit image but the values go from 1 to 4 in your case. 4 can be represented with 3 bits (4 in binary is 100). Then there's a color map with it that specifies what each RGB color will be for the values 1, 2, 3, and 4. If you specified 6 you'd get 6 colors, not 64 which is what 6 bits would be. Why do you think you need 4 bits? Why did you not take my advise? You do know, right, that even if the values are less than 8 bits, the values are stored in a uint8 variable which means it will be 8 bits? You can only get 4 bits if you store it in a compressed manner, like with imwrite and tell it to use PNG or some other compressed format. And you would not be guaranteed of getting exactly 4 because you don't really have control over how imwrite() does its compressing. You could do it yourself but I don't want to get into that because I don't think it's necessary for you.
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!