This is a follow up to my previous post here
I'm using the following lines of code to convert the data type(from uint16 to uint8) of z-stack images in MATLAB
%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
In the documentation available here it is mentioned that
im2uint8(I) converts the grayscale, RGB, or binary image I to uint8, rescaling or offsetting the data as necessary
I would like to know if it is possible to rescale the data before converting the datatype to uint8 and how this rescaling can be done.
Suggestions will be really helpful.
EDIT: Plotting the histogram of the image data gives the following
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)