How to save 12 bit PNG images

22 vues (au cours des 30 derniers jours)
Happy PhD
Happy PhD le 6 Nov 2018
Modifié(e) : Akshay Khadse le 19 Nov 2018
Hi, I have a grayscale camera that takes 8 and 12 bit images. Im taking images via MATLAB gentl. I noticed that imwrite saves the image as 16-bit PNG files. I was wondering if this affects the intensity for each pixel in the picture someway? Is it ok that it saves as 16 bit image? I notied that my almost maxed out intensity scale (4049 = 12 bit) looks very pale in the saved 16-bit images.
  2 commentaires
Jan
Jan le 6 Nov 2018
How do you import the images? I do not know "MATLAB gentl". If the image is store in double format, the output should scale the intensities automatically. But perhaps you import the data as UINT16 with the 4 last bit unused?
Happy PhD
Happy PhD le 6 Nov 2018
I basically use the app "Image Acquisition" with the following code. I have a GigE Camera connected to the computer.
% % Calling the camera
vid = videoinput('gentl', 1, 'Mono12');
src = getselectedsource(vid);
% .. + some code to set exposure time and frames etc ...
% % Taking images
start(vid);
img_var = getdata(vid);
% % Saving image
imwrite(img_var,'image.png')

Connectez-vous pour commenter.

Réponse acceptée

Akshay Khadse
Akshay Khadse le 19 Nov 2018
Modifié(e) : Akshay Khadse le 19 Nov 2018
MATLAB scales the image intensity values from 12-bit to 16-bit after it loads a 12-bit image via the following algorithm:
% W contains the the 12-bit data loaded from file. Data is stored in 16-bit unsigned integer
% First 4 bits are 0. Consider 12-bit pixel color value of ABC
% Then W = 0ABC
X = bitshift(W,4); % X = ABC0
Y = bitshift(W,-8); %Y = 000A
Z = bitor(X,Y); %Z = ABCA
% Z is the variable that is returned by IMREAD.
Please refer to the following MATLAB Answer for more explanation:
However, Please note that this article was originally answerd for MATLAB R2010a. The workaround mentioned might produce different results for later releases.
I am not sure if you can save 12-bit PNGs from MATLAB as the data is internally stored as 16-bit.

Plus de réponses (0)

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by