Skip to content
Snippets Groups Projects
Commit b60ad17b authored by Eric Wait's avatar Eric Wait
Browse files

Using the global readers

parent b12f12c9
No related branches found
No related tags found
No related merge requests found
function im = tiffReader(datasetName,chan,type,dirName,nameConvention,cPos,tPos,zPos)
global DatasetName OrgDir
DatasetName = datasetName;
im = [];
if (~exist('dirName','var') || isempty(dirName))
fprintf('Select Image Dir...');
dirName = uigetdir();
disp(dirName);
end
if (~exist('nameConvention','var') || isempty(nameConvention))
nameConvention = '_c%d_t%04d_z%04d%s';
cPos = 1;
tPos = 2;
zPos = 3;
end
if (~exist('chan','var')|| isempty(chan))
chan = 0;
end
if (~exist('type','var') || isempty(type))
type = 'double';
end
if (strcmp(type,'double'))
bytes = 8;
elseif (strcmp(type,'uint8'))
bytes = 1;
else
error('Type not implemented');
end
OrgDir = dirName;
dList = dir(fullfile(dirName,'*.tif*'));
mxC = 0;
mxT = 0;
mxZ = 0;
mxX = 0;
mxY = 0;
for i=1:length(dList)
vals = textscan(dList(i).name,[datasetName nameConvention]);
if (isempty(vals) || isempty(vals{1}) || isempty(vals{2}) || isempty(vals{3}))
continue;
end
if (mxX==0 || mxY==0)
im = imread(fullfile(dirName,dList(i).name));
mxX = size(im,2);
mxY = size(im,1);
end
c = double(vals{cPos});
t = double(vals{tPos});
z = double(vals{zPos});
if (c>mxC)
mxC = c;
end
if (t>mxT)
mxT = t;
end
if (z>mxZ)
mxZ = z;
end
end
if (chan~=0)
mxC=1;
end
fprintf('%d,%d,%d,%d,%d, %4.2fGB\n',mxY,mxX,mxZ,mxT,mxC,mxY*mxX*mxZ*mxT*mxC*bytes/1024/1024/1024);
im = zeros(1,1,1,1,1);
if (bytes==8)
im = zeros(mxY,mxX,mxZ,mxT,mxC);
elseif (bytes==1)
im = zeros(mxY,mxX,mxZ,mxT,mxC,'uint8');
end
for i=1:length(dList)
vals = textscan(dList(i).name,[datasetName nameConvention]);
if (isempty(vals) || isempty(vals{1}) || isempty(vals{2}) || isempty(vals{3}))
continue;
end
c = vals{cPos};
if (chan~=0 && c~=chan)
continue;
end
t = vals{tPos};
z = vals{zPos};
if (bytes==8)
im(:,:,z,t,c) = imread(fullfile(dirName,dList(i).name));
elseif (bytes==1)
im(:,:,z,t,c) = uint8(imread(fullfile(dirName,dList(i).name)));
end
end
function tiffWriter(image,prefix)
sizes = size(image);
numDim = length(sizes);
if numDim<5
channels = 1;
else
channels = sizes(5);
end
if numDim<4
frames = 1;
else
frames = sizes(4);
end
if numDim<3
stacks = 1;
else
stacks = sizes(3);
end
for c=1:channels
for t=1:frames
for z=1:stacks
fileName = sprintf('%s_c%d_t%04d_z%04d.tif',prefix,c,t,z);
imwrite(image(:,:,z,t,c),fileName,'tif','Compression','lzw');
end
end
end
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