将图像数据类型从uint16转换为uint8 [英] Convert image datatype from uint16 to uint8

查看:2243
本文介绍了将图像数据类型从uint16转换为uint8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个uint16数据类型的tiff图像堆栈,我想将其转换为uint8数据类型.我不确定在斐济该怎么做.

I have a tiff image stack in uint16 datatype and I’d like to convert this to uint8 datatype. I’m not sure how to do this in Fiji.

我已将堆栈加载到斐济,并且尝试在导出时更改数据类型.但是我在斐济导出选项中找不到用于指定数据类型的任何标签.

I have loaded the stack in Fiji and I tried to change the datatype while exporting. But I couldn’t find any tab in Fiji export options for specifying the datatype.

关于在斐济或另外在Python/MATLAB中执行此操作的建议将非常有帮助.

Suggestions on how to do this in Fiji or alternatively in Python/MATLAB will be really helpful.

推荐答案

在MATLAB中,可以使用im2uint8()函数将图像从uint16(无符号整数16)转换为uint8(无符号整数8).

The im2uint8() function can be used to convert the image from uint16 (unsigned integer 16) to uint8 (unsigned integer 8) in MATLAB.

Image = imread("Test_Image.tiff");
Image = im2uint8(Image);
imshow(Image);

对于具有多个图像并保存已转换/已转换图像的.tiff文件:

使用imread()函数以循环方式读取图像,第二个参数是与.tiff图像集中的图像编号相对应的第二个参数Image_Index,可用于抓取存储在文件中的整个图像数据.在appendWriteMode中使用imwrite()将允许将每个转换后的图像保存到一个文件中,在本示例中该文件名为Converted_Image.tiff.

For .tiff Files with Multiple Images and Saving Transformed/Converted Images:

Reading the images in a loop using the imread() function with second argument being the Image_Index corresponding to the image number within the .tiff image collection can be used to grab the entire image data stored in the file. Using imwrite() in append and WriteMode will allow each converted image to be saved into one file named in this example as Converted_Image.tiff.

%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

使用MATLAB版本:R2019b

这篇关于将图像数据类型从uint16转换为uint8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆