Borrar filtros
Borrar filtros

How to read JPEG image in 12 bit or 16 bit format??

6 visualizaciones (últimos 30 días)
saurabh
saurabh el 29 de Jul. de 2013
Editada: DGM el 6 de Jul. de 2024 a las 21:34
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

Respuestas (2)

Walter Roberson
Walter Roberson el 29 de Jul. de 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)

DGM
DGM el 6 de Jul. de 2024 a las 21:30
Editada: DGM el 6 de Jul. de 2024 a las 21:34
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)
ans = 'uint16'
getrangefromclass(recovered)
ans = 1x2
0 65535
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[min(recovered(:)) max(recovered(:))] % uint12-scale
ans = 1x2
0 4095
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by