Skip to content

Commit

Permalink
Fixes #1101
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Feb 20, 2024
1 parent efd7348 commit 01ed641
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public MoBIE( List< String > imagePaths, List< String > labelPaths, List< String

final SourcesFromPathsCreator sourcesCreator = new SourcesFromPathsCreator( imagePaths, labelPaths, labelTablePaths, root, grid );

final List< ImageFileSources > imageFileSources = sourcesCreator.getImageSources();
final List< ImageFileSources > imageSources = sourcesCreator.getImageSources();
final List< LabelFileSources > labelSources = sourcesCreator.getLabelSources();
Table regionTable = sourcesCreator.getRegionTable();

openImagesAndLabels( imageFileSources, labelSources, regionTable );
openImagesAndLabels( imageSources, labelSources, regionTable );
}

// open an image or object table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ private void addGridView( Dataset dataset, ArrayList< ImageFileSources > allSour
if ( regionDisplay == null )
{
// init RegionDisplay
regionDisplay = new RegionDisplay<>( this.regionTable.name() );
regionDisplay = new RegionDisplay<>( regionTable.name() );

// add table
final StorageLocation storageLocation = new StorageLocation();
storageLocation.data = this.regionTable;
final RegionTableSource regionTableSource = new RegionTableSource( this.regionTable.name() );
storageLocation.data = regionTable;
final RegionTableSource regionTableSource = new RegionTableSource( regionTable.name() );
regionTableSource.addTable( TableDataFormat.Table, storageLocation );
DataStore.addRawData( regionTableSource );

Expand All @@ -155,7 +155,7 @@ private void addGridView( Dataset dataset, ArrayList< ImageFileSources > allSour

for ( int regionIndex = 0; regionIndex < numRegions; regionIndex++ )
{
String regionName = this.regionTable.getString( regionIndex, ColumnNames.REGION_ID );
String regionName = regionTable.getString( regionIndex, ColumnNames.REGION_ID );
regionDisplay.sources.put( regionName, new ArrayList<>() );
}
}
Expand All @@ -165,7 +165,7 @@ private void addGridView( Dataset dataset, ArrayList< ImageFileSources > allSour
{
// TODO: This is brittle as it requires that the sourceNames have the same
// order as the regions in the regionTable
String regionName = this.regionTable.getString( regionIndex, ColumnNames.REGION_ID );
String regionName = regionTable.getString( regionIndex, ColumnNames.REGION_ID );
regionDisplay.sources.get( regionName ).add( sourceNames.get( regionIndex ) );
//System.out.println("Region: " + regionName + "; source: " + sourceNames.get( regionIndex ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ImageFileSources( String name, String pathRegex, Integer channelIndex, St
this.metadata = MoBIEHelper.getMetadataFromImageFile( nameToFullPath.get( metadataSource ), channelIndex );

// FIXME: move this out to a separate function
regionTable = Table.create( this.name );
regionTable = Table.create( name + " table" );
regionTable.addColumns( StringColumn.create( ColumnNames.REGION_ID, new ArrayList<>( nameToFullPath.keySet() ) ) );
regionTable.addColumns( StringColumn.create( "source_path", new ArrayList<>( nameToFullPath.values() ) ) );
}
Expand Down
56 changes: 10 additions & 46 deletions src/main/java/org/embl/mobie/lib/files/SourcesFromPathsCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,28 @@
*/
package org.embl.mobie.lib.files;

import org.apache.commons.compress.utils.FileNameUtils;
import org.embl.mobie.lib.io.FileImageSource;
import org.embl.mobie.lib.table.ColumnNames;
import org.embl.mobie.lib.transform.GridType;
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class SourcesFromPathsCreator
{
private List< ImageFileSources > imageFileSources;
private List< ImageFileSources > imageSources;
private List< LabelFileSources > labelSources;
private Table regionTable;

public SourcesFromPathsCreator( List < String > imagePaths, List < String > labelPaths, List < String > labelTablePaths, String root, GridType grid )
{
// images
//
imageFileSources = new ArrayList<>();
imageSources = new ArrayList<>();
for ( String imagePath : imagePaths )
{
final FileImageSource fileImageSource = new FileImageSource( imagePath );
imageFileSources.add( new ImageFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, grid ) );
imageSources.add( new ImageFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, grid ) );
}

// segmentation images
Expand All @@ -74,47 +69,11 @@ public SourcesFromPathsCreator( List < String > imagePaths, List < String > labe
labelSources.add( new LabelFileSources( fileImageSource.name, fileImageSource.path, fileImageSource.channelIndex, root, grid ) );
}
}

// region table
//
regionTable = Table.create( "image table" );
final List< String > regions = imagePaths.stream().map( path -> FileNameUtils.getBaseName( path ) ).collect( Collectors.toList() );
regionTable.addColumns( StringColumn.create( ColumnNames.REGION_ID, regions ) );
}

// TODO consider adding back the functionality of groups for sorting the grid
// final List< String > groups = MoBIEHelper.getGroupNames( regex );
// if ( groups.size() > 0 )
// {
// final Pattern pattern = Pattern.compile( regex );
// final Set< String > set = new LinkedHashSet<>();
// for ( String path : paths )
// {
// final Matcher matcher = pattern.matcher( path );
// matcher.matches();
// set.add( matcher.group( 1 ) );
// }
//
// final ArrayList< String > categories = new ArrayList<>( set );
// final int[] numSources = new int[ categories.size() ];
// grid.positions = new ArrayList<>();
// for ( String source : sources )
// {
// final Matcher matcher = pattern.matcher( source );
// matcher.matches();
// final int row = categories.indexOf( matcher.group( rowGroup ) );
// final int column = numSources[ row ];
// numSources[ row ]++;
// grid.positions.add( new int[]{ column, row } );
// }
// }
// }
// else
// {

public List< ImageFileSources > getImageSources()
{
return imageFileSources;
return imageSources;
}

public List< LabelFileSources > getLabelSources()
Expand All @@ -124,6 +83,11 @@ public List< LabelFileSources > getLabelSources()

public Table getRegionTable()
{
return regionTable;
// all images should be shown on the same grid,
// thus we just return one of the region tables
if ( ! imageSources.isEmpty() )
return imageSources.get( 0 ).getRegionTable();
else
return labelSources.get( 0 ).getRegionTable();
}
}
17 changes: 17 additions & 0 deletions src/test/java/debug/DebugIssue1101.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package debug;

import net.imagej.ImageJ;
import org.embl.mobie.command.open.OpenMultipleImagesAndLabelsCommand;

import java.io.File;

public class DebugIssue1101
{
public static void main( String[] args )
{
new ImageJ().ui().showUI();
final OpenMultipleImagesAndLabelsCommand command = new OpenMultipleImagesAndLabelsCommand();
command.image0 = new File( "/Users/tischer/Downloads/example-png-no-open/iso.*.png" );
command.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*-
* #%L
* Fiji viewer for MoBIE projects
* %%
* Copyright (C) 2018 - 2023 EMBL
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.embl.mobie.command;

import net.imagej.ImageJ;
import org.embl.mobie.command.open.OpenImageAndLabelsCommand;
import org.embl.mobie.command.open.OpenMultipleImagesAndLabelsCommand;

import java.io.File;

public class OpenIlastikImagesAndSegmentationsCommandTest
{
static { net.imagej.patcher.LegacyInjector.preinit(); }

public static void main( String[] args )
{
new ImageJ().ui().showUI(); // initialise SciJava Services

final OpenMultipleImagesAndLabelsCommand command = new OpenMultipleImagesAndLabelsCommand();
command.image0 = new File( "src/test/resources/ilastik-multiple/raw/iso.*.png" );
command.image1 = new File( "src/test/resources/ilastik-multiple/pc/iso..*_Probabilities.h5" );
command.labels0 = new File( "src/test/resources/ilastik-multiple/oc/iso..*_Object Identities.h5" );
command.table0 = new File( "src/test/resources/ilastik-multiple/oc/iso..*_table.csv" );
command.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package projects.colony_detection_anavo;

import net.imagej.ImageJ;
import org.embl.mobie.command.open.OpenTableCommand;

import java.io.File;

public class OpenColonyObjectsTable
{
public static void main( String[] args )
{
new ImageJ().ui().showUI();
final OpenTableCommand command = new OpenTableCommand();
command.root = new File( "/Users/tischer/Desktop/moritz/HCT116_dataset-wells" );
command.table = new File( "/Users/tischer/Desktop/moritz/HCT116_dataset-wells/colony_table.csv" );
command.images = "file_name";
command.labels = "labels_file_name";
command.removeSpatialCalibration = true;
command.run();
}
}
3 changes: 3 additions & 0 deletions src/test/resources/ilastik-multiple/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This data is courtesy of the FlyEM project, HHMI Janelia Research Campus

Derived data created using ilastik 1.4.1b13 by Dominik Kutra
Binary file not shown.
Loading

0 comments on commit 01ed641

Please sign in to comment.