![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173999/image.png)
Convert bitdepth of png image
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
berkaoui sara
am 17 Mär. 2015
Bearbeitet: DGM
am 9 Jul. 2024
How to convert the image with the following information: ColorType: truecolor Format: png bitDepth: 24
to a png grayscale image with bitdepth=8 in matlab ?
0 Kommentare
Akzeptierte Antwort
Christiaan
am 18 Mär. 2015
Bearbeitet: DGM
am 9 Jul. 2024
Dear Sara,
You can use the function imfinfo to get i.e. the bit depth of the image. With the function rgb2gray you can convert your RGB image into a grey image.
An example how to perform a RGB (24 bitDepth) to a grayscale (8 bitDepth) is shown below:
clc;clear all;close all;
[RGB,map_RGB] = imread('bitdepth_24bpp_580.png');
RGB_info = imfinfo('bitdepth_24bpp_580.png');
RGB_BitDepth_original = RGB_info.BitDepth
Gray= rgb2gray(RGB);
imwrite(Gray,'imagegrey.png');
grey_info = imfinfo('imagegrey.png');
Grey_BitDepth = grey_info.BitDepth
figure(1);
subplot(2,1,1);imshow(RGB,map_RGB);
subplot(2,1,2);imshow(Gray);
The image that I used can be found in the attachment.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173999/image.png)
Good Luck! Christiaan van Ommeren
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!