How to convert .mat file to .tif file?

16 ビュー (過去 30 日間)
Haytham Ali
Haytham Ali 2022 年 1 月 17 日
コメント済み: Image Analyst 2022 年 1 月 17 日
Hi all
I have 3D image divided inot slices every slice saved inot file.mat
I want to save all of these slices inot file.TIF
How can I do this ??

回答 (1 件)

Image Analyst
Image Analyst 2022 年 1 月 17 日
s = load('yourFile.mat');
image3d = s.image3d; % Whatever it's called.
[rows, columns, slices] = size(image3d)
outputFolder = pwd; % Wherever you want.
for slice = 1 : slices
thisSlice = image3d(:, :, slice);
baseFileName = sprintf('Slice %d.tif', slice);
fullFileName = fullfile(outputFolder, baseFileName);
imwrite(thisSlice, fullFileName);
end
  2 件のコメント
Haytham Ali
Haytham Ali 2022 年 1 月 17 日
@Image Analyst Thank you
I dont have 3D image I have only slices of this 3D every slice saved into slice1.mat, slice2.mat,....slice n .mat
I want to convert every one from these slices into slice1.tif, slice2.tif,....slice n .tif
Image Analyst
Image Analyst 2022 年 1 月 17 日
s = load('yourFile.mat');
image3d = s.image3d; % Whatever it's called.
[rows, columns, slices] = size(image3d)
inputFolder = pwd; % Wherever you want.
outputFolder = pwd; % Wherever you want.
for slice = 1 : slices
% Read in image from mat file.
baseFileName = sprintf('Slice %d.mat', slice);
fullFileName = fullfile(inputFolder, baseFileName);
if ~isfile(fullFileName)
continue; % Skip it if it does not exist.
end
fprintf('Reading %s.\n', fullFileName)
s = load(fullFileName)
thisSlice = s.theImage; % or whatever it's called.
% Write out as a TIFF format image file.
baseFileName = sprintf('Slice %d.tif', slice);
fullFileName = fullfile(outputFolder, baseFileName);
fprintf('Writing %s.\n', fullFileName)
imwrite(thisSlice, fullFileName);
end

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

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by