Commit f1302971 authored by Mark Winter's avatar Mark Winter

Try to detect image sequences that do not conform to LEVER naming guidelines.

parent 8c1fdaf6
......@@ -37,7 +37,7 @@ function renameStruct = BuildRenameStruct(imageName)
[startMatch,tokMatch] = regexpi(fileName, paramPattern, 'start','tokens');
% If there are multiple matches to the parameter type, take only the one that's furthest in the name.
bFoundParams = cellfun(@(x)(~isempty(x)),startMatch);
bFoundParams = cellfun(@(x)(~isempty(x)), startMatch);
validStarts = cellfun(@(x)(x(end)), startMatch(bFoundParams));
validParams = cellfun(@(x)(x{end}{1}), tokMatch(bFoundParams), 'UniformOutput',false);
......
......@@ -27,25 +27,34 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [bNeedsExport,bWriteable,renameStruct] = CheckExportImages(rootDir,fileName)
function [bNeedsExport,bTifSequence,bInPlace,renameStruct] = CheckExportImages(rootDir,filename)
bNeedsExport = false;
bWriteable = false;
bTifSequence = false;
bInPlace = false;
renameStruct = [];
[~,chkName,chkExt] = fileparts(fileName);
[~,chkName,chkExt] = fileparts(filename);
if ( any(strcmpi(chkExt,{'.tif','.tiff'})) )
jsonList = dir(fullfile(rootDir,[chkName '*.json']));
if ( ~isempty(jsonList) )
return;
end
renameStruct = Load.BuildRenameStruct(fileName);
bTifSequence = checkSequence(rootDir, filename);
renameStruct = Load.BuildRenameStruct(filename);
end
bWriteable = ~isempty(renameStruct) && checkWriteable(rootDir);
bInPlace = ~isempty(renameStruct) && checkWriteable(rootDir);
bNeedsExport = true;
end
function bSequence = checkSequence(rootDir, filename)
fileBlob = regexprep(filename, '\d+', '*');
fileList = dir(fullfile(rootDir,fileBlob));
bSequence = (length(fileList) > 1);
end
function bCanWrite = checkWriteable(rootDir)
bCanWrite = false;
......
......@@ -22,14 +22,15 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [subPaths,needsExport,renamable] = CheckFolderExport(rootDir)
[subPaths,needsExport,renamable] = recursiveCheckExport(rootDir,'');
function [subPaths,needsExport,renamable,ambiguous] = CheckFolderExport(rootDir)
[subPaths,needsExport,renamable,ambiguous] = recursiveCheckExport(rootDir,'');
end
function [subPaths,needsExport,renamable] = recursiveCheckExport(rootDir,subDir)
function [subPaths,needsExport,renamable,ambiguous] = recursiveCheckExport(rootDir,subDir)
subPaths = {};
needsExport = false(0);
renamable = false(0);
ambiguous = false(0);
dirList = dir(fullfile(rootDir,subDir));
......@@ -59,6 +60,7 @@ function [subPaths,needsExport,renamable] = recursiveCheckExport(rootDir,subDir)
subPaths = cellfun(@(x)(fullfile(subDir,x)),jsonNames(bValid),'UniformOutput',false);
needsExport = false(nnz(bValid),1);
renamable = false(nnz(bValid),1);
ambiguous = false(nnz(bValid),1);
end
%% Handle folders of TIFs that don't require export or are renamable stacks
......@@ -68,11 +70,18 @@ function [subPaths,needsExport,renamable] = recursiveCheckExport(rootDir,subDir)
tifNames = filenames(bTIF);
if ( ~isempty(tifNames) )
% If these appear to be renameable tifs don't bother with subdirectories
[bNeedsExport,bWriteable,renameStruct] = Load.CheckExportImages(fullfile(rootDir,subDir),tifNames{1});
[bNeedsExport,bSequence,bInPlace,renameStruct] = Load.CheckExportImages(fullfile(rootDir,subDir),tifNames{1});
if ( bSequence && isempty(renameStruct) )
subPaths = {fullfile(subDir,tifNames{1})};
needsExport = bNeedsExport;
ambiguous = true;
return;
end
if ( ~isempty(renameStruct) )
subPaths = {fullfile(subDir,tifNames{1})};
needsExport = bNeedsExport;
renamable = bWriteable;
renamable = bInPlace;
return;
end
......@@ -86,15 +95,17 @@ function [subPaths,needsExport,renamable] = recursiveCheckExport(rootDir,subDir)
subPaths = [subPaths; cellfun(@(x)(fullfile(subDir,x)),exportNames,'UniformOutput',false)];
needsExport = [needsExport; true(length(exportNames),1)];
renamable = [renamable; false(length(exportNames),1)];
ambiguous = [ambiguous; false(length(exportNames),1)];
end
%% Deal with further subdirectories
for i=1:length(pathList)
nextSubDir = fullfile(subDir,pathList(i).name);
[newPaths,chkExport,chkRename] = recursiveCheckExport(rootDir,nextSubDir);
[newPaths,chkExport,chkRename,chkAmbiguous] = recursiveCheckExport(rootDir,nextSubDir);
subPaths = [subPaths; newPaths];
needsExport = [needsExport; chkExport];
renamable = [renamable; chkRename];
ambiguous = [ambiguous; chkAmbiguous];
end
end
......@@ -25,7 +25,7 @@
function exportRoot = FolderExport(rootDir)
exportRoot = rootDir;
[subPaths,needsExport,renamable] = Load.CheckFolderExport(rootDir);
[subPaths,needsExport,renamable,ambiguous] = Load.CheckFolderExport(rootDir);
if ( isempty(subPaths) )
return;
end
......@@ -35,6 +35,17 @@ function exportRoot = FolderExport(rootDir)
return;
end
if ( any(ambiguous) )
exportRoot = '';
msgbox({'The directories appear to contain image sequences.',...
'Image sequences must conform to LEVER name guidelines.',...
'Please use IrfanView or another tool to rename the images.',...
'',...
'Image name format: <DatasetName>_c%02d_t%04d_z%04d.tif'},...
'Export Error', 'Warn');
return;
end
% Allow an inplace update if all exports are renamable
exportRenames = renamable(needsExport);
exportPaths = subPaths(needsExport);
......
......@@ -23,7 +23,9 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function jsonPath = ImageExportDialog(rootDir,filename)
[bNeedsExport,bWriteable,renameStruct] = Load.CheckExportImages(rootDir,filename);
jsonPath = '';
[bNeedsExport,bSequence,bInPlace,renameStruct] = Load.CheckExportImages(rootDir,filename);
if ( ~bNeedsExport )
[~,chkName] = fileparts(filename);
jsonList = dir(fullfile(rootDir,[chkName '*.json']));
......@@ -31,7 +33,17 @@ function jsonPath = ImageExportDialog(rootDir,filename)
return;
end
exportDir = Load.ExportLocationDialog(rootDir, bWriteable);
if ( bSequence && isempty(renameStruct) )
msgbox({'The selected image appears to be part of an image sequence.',...
'Image sequences must conform to LEVER name guidelines.',...
'Please use IrfanView or another tool to rename the sequence.',...
'',...
'Image name format: <DatasetName>_c%02d_t%04d_z%04d.tif'},...
'Export Error', 'Warn');
return;
end
exportDir = Load.ExportLocationDialog(rootDir, bInPlace);
if ( isempty(exportDir) )
return;
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment