Skip to content

Commit

Permalink
Implement improve image path parsing for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Mar 5, 2024
1 parent 6a9cc35 commit a042689
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/embl/mobie/lib/color/lut/GlasbeyARGBLut.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.imglib2.type.numeric.ARGBType;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

/**
* Modified version of Glasbey LUT,
Expand Down Expand Up @@ -62,8 +63,15 @@ public GlasbeyARGBLut( int alpha )
@Override
public int getARGB( double x )
{
final int index = ( int ) Math.ceil( x * ( numColors - 1 ) );
return indices.get( index );
try
{
final int index = ( int ) Math.ceil( x * ( numColors - 1 ) );
return indices.get( index );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
}

@Override
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/org/embl/mobie/lib/files/ImageFileSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import ij.IJ;
import net.imglib2.realtransform.AffineTransform3D;
import org.apache.commons.io.FilenameUtils;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.lib.MoBIEHelper;
import org.embl.mobie.lib.io.TableImageSource;
import org.embl.mobie.lib.source.Metadata;
Expand Down Expand Up @@ -111,6 +112,7 @@ public ImageFileSources( String name, Table table, String imageColumn, Integer c
nameToPath = new LinkedHashMap<>(); // needed for joining the tables below when creating the region table

int numRows = table.rowCount();

if ( imageColumn.contains( "_IMG" ) )
{
// Automic table
Expand All @@ -132,26 +134,20 @@ public ImageFileSources( String name, Table table, String imageColumn, Integer c
}
}
}
else if ( imageColumn.startsWith( "FileName_" ) )
else if ( isCellProfilerColumn( imageColumn, table ) )
{
TableImageSource tableImageSource = new TableImageSource( imageColumn );

// Deal with CellProfiler tables
String postfix = tableImageSource.columnName.substring("FileName_".length());
String postfix = imageColumn.substring("FileName_".length());
String folderColumn = "PathName_" + postfix;
if (table.containsColumn( folderColumn ) ) {
StringColumn absolutePathColumn =
table.stringColumn( folderColumn )
.concatenate( File.separator )
.concatenate( table.stringColumn( tableImageSource.columnName ) );
absolutePathColumn.setName("AbsolutePath_" + postfix);
table.addColumns(absolutePathColumn);
root = null; // the paths are now absolute
tableImageSource = new TableImageSource( tableImageSource.name, "AbsolutePath_" + postfix, tableImageSource.channelIndex, pathMapping );
}

imageFileSources.add( new ImageFileSources( tableImageSource.name, table, tableImageSource.columnName, tableImageSource.channelIndex, root, pathMapping, gridType ) );

for ( int rowIndex = 0; rowIndex < numRows; rowIndex++ )
{
String fileName = table.getString( rowIndex, imageColumn );
String folder = table.getString( rowIndex, folderColumn );
String path = IOHelper.combinePath( folder, fileName );
String imageName = createImageName( channelIndex, fileName );
nameToFullPath.put( imageName, applyPathMapping( pathMapping, path ) );
nameToPath.put( imageName, fileName );
}
}
else
{
Expand All @@ -171,6 +167,17 @@ else if ( imageColumn.startsWith( "FileName_" ) )
dealWithTimepointsInObjectTableIfNeeded( name, table, imageColumn );
}

protected static boolean isCellProfilerColumn( String column, Table table )
{
if ( ! column.startsWith( "FileName_" ) ) return false;

String postfix = column.substring("FileName_".length());
String folderColumn = "PathName_" + postfix;
boolean containsFolderColumn = table.containsColumn( folderColumn );

return containsFolderColumn;
}

protected static List< String > getFullPaths( String regex, String root )
{
if ( root != null )
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/embl/mobie/lib/files/LabelFileSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public LabelFileSources( String name, Table table, String columnName, Integer ch
}
}

public LabelFileSources( String name, String labelsPath, Integer channelIndex, String root, String pathMapping, GridType grid )
public LabelFileSources( String name, String labelsPath, Integer channelIndex, String root, GridType grid )
{
super( name, labelsPath, channelIndex, root, pathMapping, grid );
super( name, labelsPath, channelIndex, root, grid );
}


public LabelFileSources( String name, String path, Integer channelIndex, String labelTablePath, String root, String pathMapping, GridType grid )
public LabelFileSources( String name, String path, Integer channelIndex, String labelTablePath, String root, GridType grid )
{
super( name, path, channelIndex, root, pathMapping, grid );
super( name, path, channelIndex, root, grid );

final List< String > labelTablePaths = getFullPaths( labelTablePath, root );
final ArrayList< String > labelMaskNames = new ArrayList<>( nameToFullPath.keySet() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public class SourcesFromPathsCreator

public SourcesFromPathsCreator( List < String > imagePaths, List < String > labelPaths, List < String > labelTablePaths, String root, GridType grid )
{
// FIXME: Remove all the pathMapping from the Constructors here!

// images
//
imageSources = new ArrayList<>();
for ( String imagePath : imagePaths )
{
final FileImageSource fileImageSource = new FileImageSource( imagePath );
imageSources.add( new ImageFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, null, grid ) );
imageSources.add( new ImageFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, grid ) );
}

// segmentation images
Expand All @@ -64,11 +62,11 @@ public SourcesFromPathsCreator( List < String > imagePaths, List < String > labe
if ( labelTablePaths.size() > labelSourceIndex )
{
final String labelTablePath = labelTablePaths.get( labelSourceIndex );
labelSources.add( new LabelFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, labelTablePath, root, null, grid ) );
labelSources.add( new LabelFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, labelTablePath, root, grid ) );
}
else
{
labelSources.add( new LabelFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, null, grid ) );
labelSources.add( new LabelFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, grid ) );
}
}
}
Expand Down

0 comments on commit a042689

Please sign in to comment.