I have some BMP images from an optical CT scan that I need to process in matlab. Using the function imfinfo I know that my image before being read by matlab is at 16 BitDepth and is transformed to a 24 BitDepth after.
Before
FileSize: 1572918
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 1024
Height: 768
BitDepth: 16
ColorType: 'truecolor'
FormatSignature: 'BM'
NumColormapEntries: 0
Colormap: []
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 54
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 1572864
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 0
NumImportantColors: 0
After
FileSize: 2359350
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 1024
Height: 768
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: 'BM'
NumColormapEntries: 0
Colormap: []
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 54
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 2359296
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 0
NumImportantColors: 0
I need the image to be a 16 BitDepth BMP when I save it to use it in a reconstruction software. Cheers Pierre

 채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 31일
편집: Walter Roberson 2018년 2월 12일

0 개 추천

imwrite() in MATLAB cannot write 16 bits per pixel for BMP files.
Note: 16 bits per pixel for BMP files is 4 bits each for R, G, B, and Alpha (possibly not in that order.)
imwrite() for BMP can use logical (total 1 bit per pixel) or uint8 grayscale (total 8 bits per pixel) or uint8 RGB (total 24 bits per pixel.)

댓글 수: 5

Thank you for your answer. This is making it a bit more clear on why it does not work. Do you have any advice on which function I should use instead of imread and imwrite to read and write that kind of files?
Walter Roberson
Walter Roberson 2018년 1월 31일
편집: Walter Roberson 2018년 1월 31일
imread() can read the files; it is just imwrite() that cannot write them, it appears to me.
Thank you will try this. But when I call the image with imwrite(), the number of Bytes of the file that appears in the Workspace correspond to the BitmapSize of the file after I use imwrite(). Is it related or not at all. Because if it is, for me that means that imread() changes the image.
Walter Roberson
Walter Roberson 2018년 1월 31일
imread() is unpacking the 4-4-4-4 into uint8-uint8-uint8, probably with the data in the top 4 bits of the uint8.
Because the file is storing 4 bits per channel and MATLAB has no 4 bit data type, it has to unpack into larger variables if it is to separate the channels.
Pierre Bouchereau de Pury
Pierre Bouchereau de Pury 2018년 2월 12일
편집: Pierre Bouchereau de Pury 2018년 2월 12일
I'm coming back to you as I'm struggling to use the libbmp that you gave me. I'm not too sure how to load it in matlab. I downloaded the file from the link but cannot figure out how tu use them.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 1월 31일

0 개 추천

Calling imread() will NOT change the file. You must have done something to change it. How did you change the file? Did you call imwrite() or something? You must have done something.

댓글 수: 5

Thank you for your answer. What I have done is to use imread() and then imwrite() to save it to another file without changing anything and then to compare the two. In my opinion the change comes from imread and not from imwrite as the BitmapSize correspond.
Walter Roberson
Walter Roberson 2018년 1월 31일
No, the change is definite imwrite() as imwrite() does not support 16 bits per pixel.
oh ok, and do you know if there is another function that I can use to replace it?
Image Analyst
Image Analyst 2018년 1월 31일
Use imwrite() but just use another format. From the help:
"If A is of data type uint16 and the output file format supports 16-bit data (JPEG, PNG, and TIFF), then imwrite outputs 16-bit values. If the output file format does not support 16-bit data, then imwrite returns an error."
So, a PNG would be the one I'd pick. Actually from the last sentence, I'm surprised imwrite() didn't throw and error when you tried to write the 16 bit variable to a BMP image.
Walter Roberson
Walter Roberson 2018년 1월 31일
Single plane uint16 would be for grayscale (unless the target package can mathematically manipulate the 16 bits to extract the 4-bit components.) BMP with 16 bits are RGBA 4-4-4-4

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by