How to read JPEG image in 12 bit or 16 bit format??
8 次查看(过去 30 天)
显示 更早的评论
I am new to matlab as well as to community?
I want to read any JPEG image in 12 bit or 16 bit format.... I am not sure if it's possible or not.
I am trying X = imread('filname.jpg');
Thanks, Saurabh
0 个评论
回答(2 个)
Walter Roberson
2013-7-29
Yes, imread() supports 12 bit lossy format, and 12 and 16 bit lossless format.
When I look around, I do not see at the moment whether in 12 bit format it would be the leading or trailing 4 bits (of 16) that would go unused. I would tend to suspect it would be the trailing 4 bits (of 16)
0 个评论
DGM
2024-7-6
编辑:DGM
2024-7-6
I've tested this in older versions, so it should have been fine in 2013. See
Note that the available bitdepths depend on the number of image channels. Reading or writing 16b JPG is supported only for single-channel images, and is only supported for lossless encoding.
% an RGB image (uint8)
inpict = imread('peppers.png');
% create a test 12b JPG
% input must be unit-scale float
fname = 'test.jpg';
imwrite(im2double(inpict),fname,'bitdepth',12) % lossy, downsampled
%imwrite(im2double(inpict),fname,'bitdepth',12,'mode','lossless') % lossless
% read it back
recovered = imread(fname);
% show the image
imshow(recovered)
% the class and range of the data
class(recovered)
getrangefromclass(recovered)
[min(recovered(:)) max(recovered(:))] % uint12-scale
It's almost impossible to see against the white page background, but there's an image there. It's just dark. Why is it dark? Well, the data is uint12-scale, and it's stored in uint16. The data maxes out at 4095, but "white" is at 65535 in uint16.
There is no native 12b integer class, so any representation of integer data in the scale [0 4095] will be improperly-scaled for its class, and you'll have to deal with all the problems that entails.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!