Skip to content
Snippets Groups Projects
Commit 796692d5 authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Add little macros for TIFF files

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@218 4c865b51-4357-4376-afb4-474e03ccb993
parent c5230e61
No related branches found
No related tags found
No related merge requests found
......@@ -134,6 +134,7 @@ function initialise_gt()
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Smoothing'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Strain'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_TomoUtils'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_TIFF'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_XML'));
addpath(fullfile(GT_MATLAB_HOME, 'FigureManagement'));
......
function gtConvertRawToTifVolume(rootdir, savefolder, filenames)
% GTCONVERTRAWTOTIFVOLUME cast raw volume data to tif without compression.
% Can cast lots of volumes to tif when reconstructed .vol files have the
% same name as the containing folder.
% The produced TIFF files are 8 bit unsigned integer type.
%
% *Usage:*
%
% gtConvertRawToTifVolume(rootdir, savefolder, filenames)
% rootdir = string containing root folder
% savefolder = string folder where the tif volumes should be saved
% filenames = string name of the containing folder, with * for several ones
%
% *Example:*
%
% gtConvertRawToTifVolume(/data/id11/inhouse/wolfgang, voltif, ti_55531*)
%
% 14 February 2012, Yoann Guilhem, guilhem@esrf.fr
cd(rootdir);
d=dir(filenames);
if ~exist(savefolder,'dir')
disp(['Folder "' savefolder '" does not exist. Creating it...']);
mkdir(savefolder);
end
for i=1:length(d)
VolFile = d(i).name;
if d(i).isdir
Type = 'folder';
VolName = VolFile;
VolFileName = fullfile(rootdir, VolFile, VolFile);
else
Type = 'file';
[tmp,VolName,] = fileparts(VolFile);
disp(['Processing on "' VolName '" volume file...']);
VolFileName = fullfile(rootdir, VolFile);
end
disp(['Processing on "' VolName '" volume ' Type '...']);
% Reading volume
Vol = HSTVolReader(VolFileName, 'xrange', 'all', 'yrange', 'all', 'zrange', 'all');
% Creating grayscale integer volume
grayNewVol = mat2gray(Vol);
intvolume = uint8(grayNewVol*255);
% Writing volume in TIFF file
TifFileName = fullfile(rootdir, savefolder, [VolName '.tif']);
if exist(TifFileName,'file')
delete(TifFileName);
end
for i=1:size(Vol,3)
imwrite(intvolume(:,:,i)', TifFileName, 'tif', 'Compression', 'none', 'writemode', 'append');
end
disp('done');
end
function vol = gtReadTifVolume(filename)
% GTREADTIFVOLUME read tif volume (stack) and store it into a matrix
%
% 14 February 2012, Yoann Guilhem, guilhem@esrf.eu
if exist(filename)
info = imfinfo(filename);
Xsize = info(1).Width;
Ysize = info(1).Height;
Zsize = numel(info);
vol = zeros(Ysize,Xsize,Zsize);
for i=1:size(vol,3)
vol(:,:,i) = imread(filename,i);
end
else
error('"%s" file does not exist!', filename);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment