Skip to content
Snippets Groups Projects
Commit 7de5fffc authored by Florian Vollrath's avatar Florian Vollrath
Browse files

cleaned mybfopenOnlyMetaData and added original authors

parent 3e05a8e5
Branches
No related tags found
No related merge requests found
function [metadatastruct] = mybfopenOnlyMetaData( fileName, varargin )
function [metadatastruct] = mybfopenOnlyMetaData( fileName)
% Extracts Meta Data from files
% 27.05.2013 (Version 1.0)
% Authors:
% Andre Zeug (zeug.andre@mh-hannover.de)
% Malte Butzlaff (Butzlaff.Malte@mh-hannover.de)
%
% This software is for non-commercial use only.
%% parsing imput parameters
p = inputParser;
p.StructExpand = true; % if we allow parameter structure expanding
%p.CaseSensitivity = false; % enables or disables case-sensitivity when matching entries in the argument list with argument names in the schema. Default, case-sensitive matching is disabled (false).
p.KeepUnmatched = true; % controls whether MATLAB throws an error (false) or not (true) when the function being called is passed an argument that has not been defined in the inputParser schema for this file.
% p.FunctionName = ['mybfopen v.' mybfopen_version ' (' mybfopen_date ')']; % stores a function name that is to be included in error messages that might be thrown in the process of validating input arguments to the function.
p.addParameter('verbose' , true , @(x)(islogical(x) || any(x==[0 1 2])));
p.addParameter('gui' , true , @(x)(islogical(x) || any(x==[0 1 2 3])));
p.addParameter('timestamp' , false , @(x)(isnumeric(x)));
%p.addParamValue('img_first' , false , @(x)(islogical(x) || (isscalar(x) && x>=0 && mod(x,1)==0)));
%p.addParamValue('img_last' , false , @(x)(islogical(x) || (isscalar(x) && x>=0 && mod(x,1)==0)));
p.parse(varargin{:});
par = p.Results;
% setting clock
if par.verbose
if ~par.timestamp
par.timestamp = tic;
end
t1 = toc(par.timestamp); % starts timer for verbose
end
% fprintf('\n')
% if par.verbose; t1 = output(sprintf('mybfopen: Start mybfopen v. %s (%s)!',...
% mybfopen_version ,mybfopen_date), whos, toc(par.timestamp), t1); end
% add unmached structure elements
s = fieldnames(p.Unmatched);
for n=1:length(s)
......@@ -40,11 +30,10 @@ if (nargin == 0)
else
par.fname = fileName; %[pwd '\' fileName]; % require to replace since receive error when fileName contains full path
end
% if par.verbose; t1 = output(sprintf('mybfopen: read file ''%s''',fileName), whos, toc(par.timestamp), t1); end
jPath = javaclasspath('-all');
isLociTools = cellfun(@(x) ~isempty(regexp(x, '.*bioformats_package.jar$', 'once')),jPath);
if ~any(isLociTools);
if ~any(isLociTools)
locipath = which('bioformats_package.jar');
if isempty(locipath)
locipath = fullfile(fileparts(mfilename('fullpath')), 'bioformats_package.jar');
......@@ -55,7 +44,6 @@ if ~any(isLociTools);
javaaddpath(locipath);
% if par.verbose; t1 = output('mybfopen: added ''bioformats_package.jar'' to java path', whos, toc(par.timestamp), t1); end
end
% if par.verbose; t1 = output('mybfopen: generate loci class object', whos, toc(par.timestamp), t1); end
% Create a loci.formats.ReaderWrapper object
r = javaObject('loci.formats.ChannelSeparator', ...
......@@ -64,7 +52,6 @@ r = javaObject('loci.formats.ChannelSeparator', ...
OMEXMLService = javaObject('loci.formats.services.OMEXMLServiceImpl');
r.setMetadataStore(OMEXMLService.createOMEXMLMetadata());
r.setId(par.fname);
% if par.verbose; t1 = output('mybfopen: file opened', whos, toc(par.timestamp), t1); end
% extract metadata table for this series
metadataOME = r.getMetadataStore();
......@@ -75,57 +62,8 @@ iDZ = metadataOME.getPixelsSizeZ(0).getValue();
iDT = metadataOME.getPixelsSizeT(0).getValue();
imageDims = [iDY iDX iDZ iDC iDT];
numImages = r.getImageCount();
% if par.verbose; t1 = output('mybfopen: main parameter read, start data reading', whos, toc(par.timestamp), t1); end
% Get pixel information (type, etc.)
pixelType = r.getPixelType();
bpp = javaMethod('getBytesPerPixel', 'loci.formats.FormatTools', pixelType);
fp = javaMethod('isFloatingPoint', 'loci.formats.FormatTools', pixelType);
sgn = javaMethod('isSigned', 'loci.formats.FormatTools', pixelType);
if sgn
stopHere
end
little = r.isLittleEndian();
% set data format according to bit depth
switch bpp
case 1; classstr = 'uint8';
case 2; classstr = 'uint16';
case 4; classstr = 'uint32';
case 8; classstr = 'uint64';
end
% allocating memory for data
% data = zeros(imageDims, classstr);
% calc bytes per image plane
% imb = bpp*iDX*iDY/1024/1024;
% generate progress bar
% if par.gui,
% h = waitbar(0,'Please wait...','Name','mybfopen: Wait for data reading!');
% iiw = 0; iio = 0; tw = toc(par.timestamp); tr1 = tw;
% end;
% data import loop
% for ii = 1:numImages
% % update waitbar (in steps of 1%)
% if par.gui && 100*ii/numImages>iiw,
% tr = toc(par.timestamp) - tw;
% tre = tr/ii*numImages;
% waitbar(ii/numImages,h,...
% {sprintf('Import frame: %d / %d (%0.0f%%)',ii,numImages,100*ii/numImages);...
% sprintf('data read: % 8.2f MB/s, Time: %02d:%02d / %02d:%02d min',imb*(ii-iio)/(tr-tr1),floor(tr/60),floor(60*(tr/60 - floor(tr/60))),floor(tre/60),floor(60*(tre/60 - floor(tre/60))))});
% iiw = iiw + 1; iio = ii; tr1 = tr;
% end;
% get image
% plane = r.openBytes(ii - 1, 0, 0, iDX, iDY);
% arr = javaMethod('makeDataArray', 'loci.common.DataTools', plane, bpp, fp, little);
% zct = r.getZCTCoords(ii - 1) + 1;
% % store image in matrix
% data(:,:,zct(1),zct(2),zct(3)) = reshape(typecast(arr, classstr),[iDX iDY])';
% end
% if par.gui, delete(h); drawnow; end;
% if par.verbose; t1 = output('mybfopen: data reading finished', whos, toc(par.timestamp), t1); end
%data = reshape(data, imageDims);
%% transfer output
nout = max(nargout,1)-1;
if 1>0,
tt = par.fname;
tte=regexpi(tt,'/|\');
ttp=regexpi(tt,'\.');
......@@ -136,7 +74,7 @@ if 1>0,
tt = tt(tte(end)+1:end);
end
end
% if par.verbose; t1 = output('mybfopen: start list metadata reading', whos, toc(par.timestamp), t1); end
%% metadataList
metadataList = r.getGlobalMetadata();
metadataKeys = metadataList.keySet().iterator();
......@@ -157,7 +95,6 @@ if 1>0,
end
[~,ind] = sort(info.list(:,1));
info.list = info.list(ind,:);
% if par.verbose; t1 = output('mybfopen: metadata list sorted, generate structure', whos, toc(par.timestamp), t1); end
% generate structure out of list info
str = [];
for ii =1:size(info.list,1)
......@@ -167,7 +104,6 @@ if 1>0,
% \W: Any character that is not alphabetic, numeric, or underscore. (equivalent to [^a-zA-Z_0-9])
end
info.liststr = str;
% if par.verbose; t1 = output('mybfopen: metadata list structure generate, read OME timestamp', whos, toc(par.timestamp), t1); end
else
info.list{1,1} = 'no key';
info.list{1,2} = 'no value';
......@@ -177,7 +113,7 @@ if 1>0,
% read timestamp from OME data
Ts = zeros(numImages,1);
try
for nn=1:numImages;
for nn=1:numImages
Ts(nn) = metadataOME.getPlaneDeltaT(0,nn-1).value(); %remove .value() when using older versions of bioformats
end
info.Ts = reshape(Ts,[imageDims(3:end)]);
......@@ -206,16 +142,9 @@ if 1>0,
warning('File contains no time information')
end
end
info.OME = metadataOME;
varargout(1) = {info};
metadatastruct=info
% if par.verbose; t1 = output('mybfopen: 2nd output transfered', whos, toc(par.timestamp), t1); end
end
if nout>1,
% parameter list output
varargout(2) = {par};
% if par.verbose; t1 = output('mybfopen: 3rd output transfered', whos, toc(par.timestamp), t1); end
end
metadatastruct=info;
% close file
r.close();
% inline function for structure generation from metadatalist
......@@ -236,7 +165,6 @@ r.close();
end
else
if regexp(tt(1:tt_pos(1)-1),'^\d*$') % checks if tt is numerical
%str.(['no' tt(1:tt_pos(1)-1)]) = getStruckt(str, tt(tt_pos(1)+1:end), content);
ttn = ['no' tt(1:tt_pos(1)-1)];
else
ttn = tt(1:tt_pos(1)-1);
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment