Problem with converted TIFF image
6 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
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
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)
% even if you fixed the error, it would still change the contrast
C = uint16(mat2gray(A) * double(intmax('uint16')))
% this is just an error
D = uint16(mat2gray(A) * intmax('uint16'))
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 件)
参考
カテゴリ
Help Center および File Exchange で Image Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!