【问题标题】:How to rescale image data before converting data types如何在转换数据类型之前重新缩放图像数据
【发布时间】:2021-02-02 21:38:56
【问题描述】:

这是对我之前的帖子here的跟进

我正在使用以下代码行在 MATLAB 中将 z-stack 图像的数据类型(从 uint16 转换为 uint8)

%Multiple image tiff conversion%

File_Name = "Test_Image.tiff";
Image_Data = imfinfo(File_Name);
Number_Of_Images = length(Image_Data);


Tiff_Structure = struct('Image_File',[]);  

for Image_Index = 1: Number_Of_Images
    
      Image = imread(File_Name,Image_Index);
      Uint8_Image = im2uint8(Image);

      %For more information and plotting individual images%
      Tiff_Structure(Image_Index).Image_File = Uint8_Image;
      
      %Saving the converted images to one tiff file%
      imwrite(Uint8_Image,'Converted_Image.tiff','WriteMode','append');

end

here 可用的文档中提到

im2uint8(I) 将灰度、RGB或二值图像I转换为uint8, 根据需要重新缩放或偏移数据

我想知道在将数据类型转换为 uint8 之前是否可以重新缩放数据以及如何进行重新缩放。

Test_Image.Tiff

建议会很有帮助。

编辑: 绘制图像数据的直方图得到以下结果

img_data = imfinfo(f);
n_img = length(img_data);

imgs = cell(1, numel(img_data));
for i = 1:numel(img_data)
    imgs{i} = imread(f, i);
end
imgs = cat(3, imgs{:});
figure(1)
imhist(imgs(:), 256)

【问题讨论】:

  • 是的,im2uint8() 函数会自动重新缩放数据并相应地对所有内容进行标准化以适应 255(8 位)范围/比例。我看不出进一步重新调整的原因。该直方图看起来像是 TIFF 文件中所有图像的聚合图。我不确定你是否想要这样的直方图。

标签: matlab image-processing


【解决方案1】:

假设 Image 的值在 0-65535(16 位)范围内 将值缩放为 8 位图像:

  1. 首先将图像除以 65535 (2^16) - 这会将值范围标准化为 0-1
  2. 现在您需要重新缩放到 8 位范围的值,将图像乘以 255

基本上是这样:

scaled_image = uint8(double(Image)./65535*255)

注意:为了保持图像的动态范围,最好选择一个不同的值进行标准化,例如所有堆栈中的某个最大值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-26
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多