フィルターのクリア

Is it possible to convert a tiff image to uint16 without changing the images actual appearance?

7 ビュー (過去 30 日間)
I have a code that I am using to change some tiff images to uint16. The images look darker than the original. Is there a way to make them identical? I have attached a part of my code below.
for j = 1:length(imageFiles)
currentImage = imageFiles(j).name;
imagePath = fullfile(subfolderPath, currentImage);
outputImageName = [currentImage(1:end-5), '_converted.tiff']; % Adjusted output image name
% Read the image
img = imread(imagePath);
% Convert to unsigned 16-bit integer
img_uint16 = im2uint16(img);
% Save the image
tiffPath = fullfile(subfolderPath, outputImageName);
imwrite(img_uint16, tiffPath, 'tiff', 'Compression', 'none', 'WriteMode', 'overwrite');

採用された回答

Image Analyst
Image Analyst 2024 年 2 月 19 日
If you have a uint8 image and the values are in the range of 0-255, it seems to multiply everything by 256 (roughly) to make the new uint16 image in the range of 0-65535 if you use im2uint16():
% Read the image
img = uint8(1:100);
% Convert to unsigned 16-bit integer
img_uint16 = im2uint16(img);
maxValue = max(img_uint16, [], 'all')
maxValue = uint16 25700
If you use imshow(img, []), it should show up identically for both classes. Are you sure you're using [] in imshow? Are you sure you want to change the range of the numbers? If not, just use uint16() instead of im2uint16().
img2 = uint16(img);
maxValue = max(img2, [], 'all')
maxValue = uint16 100
In that case it might look darker if you didn't use [] (because 100 is just a small fraction of 65535 so everything will be scaled to zero before display) but if you did, it should look the same.
  3 件のコメント
Image Analyst
Image Analyst 2024 年 2 月 20 日
編集済み: Image Analyst 2024 年 2 月 20 日
Yes, like I said -- everything will be scaled to zero.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
DGM
DGM 2024 年 2 月 21 日
Don't use uint16() or uint8() unless you do the appropriate scaling as well. Since we don't have the image and we don't know what your objective is, we can't tell you what the appropriate scaling is.
IPT im2uint16(), im2uint8(), etc. presume that floating-point inputs are unit-scale. If your data is not unit-scale, and you're viewing it using imshow(myimage,[]), then you're being blinded to what the actual scale is; consequently, you're blinding yourself to what the actual brightness/contrast is. If that's what you want, then just use mat2gray() on the data prior to using im2uint16(). Otherwise, attach an example tiff and elaborate on your expectations regarding how things should be represented.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by