How to read JPEG image in 12 bit or 16 bit format??
7 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 29 Jul 2013
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 Comments
DGM
on 6 Jul 2024
Edited: DGM
on 6 Jul 2024
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 Comments
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!