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!