필터 지우기
필터 지우기

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

조회 수: 15 (최근 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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by