필터 지우기
필터 지우기

Problem with converted TIFF image

조회 수: 6 (최근 30일)
Melecia Senior
Melecia Senior 2023년 12월 14일
편집: DGM 2024년 5월 12일
I converted a png to tiff unsigned int16. The image resulting is completely black.
This a apart of my code:
% Convert to unsigned 16-bit integer
img_uint16 = uint16(double(img) / double(intmax('uint16')) * 65535);
% Save the image as TIFF
tiffPath = fullfile(subfolderPath, [currentImage(1:end-4), '_converted.tif']);
imwrite(img_uint16, tiffPath);

채택된 답변

Image Analyst
Image Analyst 2023년 12월 14일
Try
img_uint16 = uint16(double(img) / double(max(img(:))) * 65535);
or
img_uint16 = uint16(mat2gray(img) * intmax('uint16'));
  댓글 수: 1
DGM
DGM 2024년 5월 12일
편집: DGM 2024년 5월 12일
Neither of these will preserve the image contrast, and the second is a disallowed mixed-class operation and will throw an error.
A = uint8([32 224]); % not a full-range image
% contrast is improperly skewed toward white for all values
B = uint16(double(A) / double(max(A(:))) * 65535)
B = 1x2
9362 65535
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% even if you fixed the error, it would still change the contrast
C = uint16(mat2gray(A) * double(intmax('uint16')))
C = 1x2
0 65535
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% this is just an error
D = uint16(mat2gray(A) * intmax('uint16'))
Error using *
Integers can only be combined with integers of the same class, or scalar doubles.
While it's unlikely that the input class is signed integer, if it were, the first example would also cause gross data truncation, whereas the second would just cause the same contrast alteration.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 12월 14일
이동: DGM 2024년 5월 12일

카테고리

Help CenterFile Exchange에서 Image Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by