MATLAB Answers

Matrix to 12 bit image without pixel information loss

조회 수: 7(최근 30일)
Pushkal Sharma
Pushkal Sharma 2021년 3월 12일
답변: Asvin Kumar 2021년 3월 17일
I am running a pipeline which initially imports tif images (12-bit; 0 to 4095 pixel intensity value), converts values to doubles (it still stores original pixel values i.e. 0-4095) and finally do some processing. Afterwards I need to save them again as tif files for further processing on ImageJ, but it seems transferrring matrix data into image changes the original pixel values. I used imshow to generate an image and save it using Save As in the dropdown menu on matlab figure.
Is there a way to generate/store images from matrix without changing the original pixel values of a 12 bit image?

채택된 답변

Asvin Kumar
Asvin Kumar 2021년 3월 17일
imshow might internally be using imwrite and as mentioned in the description for imwrite, double values get scaled and written as 8-bit values.
Having said that, there are two ways to write TIFF files.
  1. imwrite with special N-V pairs
  2. TIFF objects
Part 1 - imwrite
imwrite can write 'uint16' values to TIFF files without any conversion.So, first trick that you could try is to cast your data from 'double' to 'uint16'. Once that's done, you can write the 'uint16' values to TIFF images following the syntax in this example. imwrite also provides some special N-V pairs for TIFF files such as 'ColorSpace', 'Compression', 'Resolution', etc.
Part 2 - TIFF objects
The options in imwrite are limited. MATLAB has something called TIFF objects which are basically a gateway to access functions of the LibTIFF Library. A list of all the functions available via TIFF objecs is provided on its doc page along with a couple of examples. Here's a link to a good article on exporting TIFF images.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by