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

GtVolView can now load tif volumes directly

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@260 4c865b51-4357-4376-afb4-474e03ccb993
parent 21a9acbd
No related branches found
No related tags found
No related merge requests found
function vol = gtReadTifVolume(filename, varargin)
function [vol, info] = gtReadTifVolume(filename, varargin)
% GTREADTIFVOLUME read tif volume (stack) and store it into a matrix [X,Y,Z]
%
% Usage: vol=gtReadTifVolume(filename,[,'xrange',xrange,'yrange',yrange,'zrange',zrange])
% Usage: [vol,info]=gtReadTifVolume(filename,[,'xrange',xrange,'yrange',yrange,'zrange',zrange])
% Use it exactly the same as gtHSTVolReader function.
%
% 14 February 2012, Yoann Guilhem, guilhem@esrf.eu
......@@ -17,79 +17,98 @@ if ~exist('filename','var')
filename = fullfile(tmp2,tmp1);
end
[fpath, fname, fext] = fileparts(filename);
% Checking existence of file extension, if not, add it
if ~length(fext)
filename = [filename '.tif'];
end
% Check existence of file
if ~exist(filename)
Mexc = MException('TIFF:wrong_file_name',['File ''' filename ''' does not exist!']);
throw(Mexc);
end
try
info = imfinfo(filename);
tifInfo = imfinfo(filename);
catch Mexc
disp('Unable to read information of selected volume.')
disp('Please check it exists in the directory.')
disp(' ')
Mexc1 = MException('TIFF:wrong_input', 'Unable to read files');
Mexc1 = MException('TIFF:wrong_input', 'Unable to read file');
Mexc1 = addCause(Mexc1, Mexc);
throw(Mexc1);
end
XTifSize = info(1).Width;
YTifSize = info(1).Height;
ZTifSize = numel(info);
fullFilename = tifInfo(1).Filename;
[fpath, fname, fext] = fileparts(fullFilename);
tifSizeX = tifInfo(1).Width;
tifSizeY = tifInfo(1).Height;
tifSizeZ = numel(tifInfo);
if strcmp(params.xrange,'all')
Xrange = 1:XTifSize;
rangeX = 1:tifSizeX;
else
Xrange = params.xrange;
rangeX = params.xrange;
end
if strcmp(params.yrange,'all')
Yrange = 1:YTifSize;
rangeY = 1:tifSizeY;
else
Yrange = params.yrange;
rangeY = params.yrange;
end
if strcmp(params.zrange,'all')
Zrange = 1:ZTifSize;
rangeZ = 1:tifSizeZ;
else
Zrange = params.zrange;
rangeZ = params.zrange;
end
XVolSize = length(Xrange);
YVolSize = length(Yrange);
ZVolSize = length(Zrange);
volSizeX = length(rangeX);
volSizeY = length(rangeY);
volSizeZ = length(rangeZ);
switch info(1).BitDepth
switch tifInfo(1).BitDepth
case 1
ftype = 'logical';
case 8
vol = zeros(XVolSize,YVolSize,ZVolSize,'uint8');
ftype = 'uint8';
case 12
vol = zeros(XVolSize,YVolSize,ZVolSize,'uint16');
ftype = 'uint16';
case 16
vol = zeros(XVolSize,YVolSize,ZVolSize,'uint16');
ftype = 'uint16';
otherwise
vol = zeros(XVolSize,YVolSize,ZVolSize);
ftype = '';
end
if ~length(ftype)
vol = zeros(volSizeX,volSizeY,volSizeZ);
elseif strcmp(ftype,'logical')
vol = false(volSizeX,volSizeY,volSizeZ,'uint8');
else
vol = zeros(volSizeX,volSizeY,volSizeZ,ftype);
end
%disp('Tiff')
%disp([info(1).Height info(1).Width numel(info)])
%disp([XTifSize YTifSize ZTifSize]);
%disp(size(imread(filename, 1)))
%disp('Tiff crop')
%disp(size(imread(filename, 1,'PixelRegion', {[Yrange(1) Yrange(end)], [Xrange(1) Xrange(end)]})))
%disp('Vol crop')
%disp(size(imread(filename, 1,'PixelRegion', {[Yrange(1) Yrange(end)], [Xrange(1) Xrange(end)]})'))
%disp([XVolSize YVolSize ZVolSize])
% Same info as HST volumes
info.volSizeX = volSizeX;
info.volSizeY = volSizeY;
info.volSizeZ = volSizeZ;
info.bytespervoxel = tifInfo(1).SamplesPerPixel * tifInfo(1).BitsPerSample / 8;
info.fpath = fpath;
info.fname_final = fullFilename;
info.byteorder = tifInfo(1).ByteOrder(1);
info.ftype = ftype;
info.fname_prefix = fname;
%tic
if nargin <= 1
for i=1:ZVolSize
vol(:,:,i) = imread(filename, Zrange(i))';
for i=1:volSizeZ
vol(:,:,i) = imread(filename, rangeZ(i))';
end
else
for i=1:ZVolSize
vol(:,:,i) = imread(filename, Zrange(i), 'PixelRegion', {[Yrange(1) Yrange(end)], [Xrange(1) Xrange(end)]})';
for i=1:volSizeZ
vol(:,:,i) = imread(filename, rangeZ(i), 'PixelRegion', {[rangeY(1) rangeY(end)], [rangeX(1) rangeX(end)]})';
% This second method should be faster but in fact...
%vol(:,:,i) = imread(filename, Zrange(i), 'Info', info, 'PixelRegion', {[Yrange(1) Yrange(end)], [Xrange(1) Xrange(end)]})';
%vol(:,:,i) = imread(filename, rangeZ(i), 'Info', info, 'PixelRegion', {[rangeY(1) rangeY(end)], [rangeX(1) rangeX(end)]})';
end
end
%toc
end
......@@ -668,9 +668,11 @@ classdef GtVolView < GtBaseGuiElem
% also the format
if isa(vol, 'char') % user has specified a filename
[~, ~, ext] = fileparts(vol);
switch (ext) % TIFF should be added as well
switch (ext)
case '.edf'
[vol, info] = edf_read(vol);
case '.tif'
[vol, info] = gtReadTifVolume(vol);
otherwise
[vol, info] = gtHSTVolReader(vol);
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