matrix to 12-bit monochrome jpg

1 次查看(过去 30 天)
grant
grant 2023-5-18
回答: Sourabh 2025-1-23
Hello,
I have raw 12-bit monochrome data (stored as an integer) in a file which can be read into matlab.
I have extracted a sample 3x3.
The following produces a file that can not be read by any viewer. ie. XnViewMP, Irfanview and many more.
Even changing BitDepth to 16 does still not work.
x=[1003 647 1011;668 982 677; 977 678 973];
y= uint16(x);
imwrite(y,'example.jpg', 'BitDepth', 12, 'Quality', 100);
Any help would be appreciated.
I can use any format as long as it is 12-bit monochrome.
Thank you Grant

回答(1 个)

Sourabh
Sourabh 2025-1-23
Hey @grant
I could reproduce the issue in MATLAB R2023a. Upon further investigation I found that standard image viewers, such as XnViewMP and IrfanView, do not support 12-bit JPEG images due to limited adoption of this format in common software and hardware. Most image viewers widely use 8-bit JPEGs or 16-bit formats like TIFF for higher bit depth.
As a workaround I suggest using the “imread” and “imshow” function to view the 12-bit monochrome JPG image in MATLAB.
Please refer to the following example:
x = [1003 647 1011; 668 982 677; 977 678 973];
y = uint16(x);
imwrite(y, 'example.jpg', 'BitDepth', 12, 'Quality', 100);
img = imread('example.jpg');
imshow(img, []);
Alternatively, the 12-bit monochrome image can be saved in an uncompressed TIFF format.
Modify the imwrite function as follows:
imwrite(y, 'example.tiff', 'Compression', 'none');
For more information regarding “imwrite function, kindly refer the following documentation:

Community Treasure Hunt

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

Start Hunting!

Translated by