Skip to content

Commit

Permalink
Fixes ##1163
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 20, 2024
1 parent f446f17 commit 0d87181
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 102 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.embl.mobie</groupId>
<artifactId>mobie-viewer-fiji</artifactId>
<version>5.0.9</version>
<version>5.0.11</version>

<!-- force javadoc generation to fetch errors: -->
<!-- mvn javadoc:javadoc | grep error -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public abstract class AbstractTransformationCommand extends DynamicCommand imple
public String selectedSourceName;

@Parameter ( label = "Transformed image(s) suffix",
description = "Upon transformation this suffix will be appended to the moving image(s).\n" +
"Carefully choose a meaningful suffix here that will create a unique new image name.")
description = "Upon transformation this suffix will be appended to the moving image name.\n" +
"Carefully choose a meaningful suffix here that will create a unique new image name.\n" +
"If you leave this empty the input image view will be overwritten.")
public String suffix = "transformed";

// Too complex to maintain right now
Expand Down Expand Up @@ -134,7 +135,9 @@ protected void createAndSaveAffineTransformedImages(
{
for ( Image< ? > movingImage : movingImages )
{
String transformedImageName = movingImage.getName() + "-" + suffix;
String transformedImageName = movingImage.getName();
if ( ! suffix.isEmpty() )
transformedImageName += "-" + suffix;

AffineTransformation affineTransformation = new AffineTransformation(
suffix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void startManualTransform()
transformationEditor.setActive( true );

getInfo().getMutableInput( "status", String.class )
.setValue( this, "Status: You are transforming " + selectedSourceName + "...");
.setValue( this, "Status: You are transforming \"" + selectedSourceName + "\"...");
}

private void acceptManualTransform()
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/org/embl/mobie/command/open/OpenBlobsCommand.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.MoBIEHelper;
import org.embl.mobie.lib.io.DataFormats;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

import java.io.File;
import java.io.IOException;


Expand All @@ -46,7 +48,7 @@ public class OpenMoBIEProjectCommand implements Command
static { net.imagej.patcher.LegacyInjector.preinit(); }

@Parameter ( label = "Project Location" )
public String projectLocation = "https://github.com/mobie/platybrowser-datasets";
public File projectLocation = new File( "https://github.com/mobie/platybrowser-datasets" );

@Parameter ( label = "Preferentially Fetch Data From", choices = {"Remote", "Local"} )
public String location = "Remote";
Expand All @@ -60,7 +62,7 @@ public void run()

try
{
new MoBIE( projectLocation, settings );
new MoBIE( MoBIEHelper.toURI( projectLocation ), settings );
}
catch ( IOException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@
package org.embl.mobie.command.open.project;

import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.MoBIEHelper;
import org.embl.mobie.lib.ThreadHelper;
import org.embl.mobie.lib.bdv.view.SliceViewer;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

import java.io.File;

@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN_PROJECT + "Open MoBIE Project Expert Mode..." )
public class OpenMoBIEProjectExpertCommand extends OpenMoBIEProjectBranchCommand
{
@Parameter ( label = "Image Data Location" )
public String imageDataLocation = "https://github.com/platybrowser/platybrowser";
public File imageDataLocation = new File( "https://github.com/platybrowser/platybrowser" );

@Parameter ( label = "Table Data Location" )
public String tableDataLocation = "https://github.com/platybrowser/platybrowser";
public File tableDataLocation = new File( "https://github.com/platybrowser/platybrowser" );

@Parameter ( label = "Table Data Branch" )
public String tableDataBranch = "master";
Expand All @@ -60,8 +63,8 @@ public void run()
ThreadHelper.setNumIoThreads( numThreads );

settings.gitProjectBranch( projectBranch )
.imageDataLocation( imageDataLocation )
.tableDataLocation( tableDataLocation )
.imageDataLocation( MoBIEHelper.toURI( imageDataLocation ) )
.tableDataLocation( MoBIEHelper.toURI( tableDataLocation ) )
.gitTablesBranch( tableDataBranch );

super.run();
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/org/embl/mobie/lib/MoBIEHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import net.imglib2.Cursor;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Intervals;
import net.imglib2.util.ValuePair;
import net.imglib2.view.Views;
import org.embl.mobie.io.ImageDataOpener;
import org.embl.mobie.io.github.GitHubUtils;
Expand All @@ -47,10 +49,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -312,6 +311,25 @@ public static List< String > getFullPaths( String regex, String root )
}
}

public static double[] estimateMinMax(
RandomAccessibleInterval<? extends RealType<?> > rai)
{
Cursor<? extends RealType<?>> cursor = Views.iterable(rai).cursor();
if (!cursor.hasNext()) return new double[]{0, 255};
long stepSize = Intervals.numElements(rai) / 10000 + 1;
int randomLimit = (int) Math.min(Integer.MAX_VALUE, stepSize);
Random random = new Random(42);
double min = cursor.next().getRealDouble();
double max = min;
while (cursor.hasNext()) {
double value = cursor.get().getRealDouble();
cursor.jumpFwd(stepSize + random.nextInt(randomLimit));
min = Math.min(min, value);
max = Math.max(max, value);
}
return new double[]{min, max};
}

public static <T extends RealType<T> > double[] computeMinMax( RandomAccessibleInterval<T> rai) {
Cursor<T> cursor = Views.iterable(rai).cursor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ private void addButtonsPanel() {

remoteButton.addActionListener( e ->
{
new Thread( () -> { remoteMetadataSettingsDialog(); } ).start();
new Thread( this::remoteMetadataSettingsDialog ).start();
} );

openMoBIEButton.addActionListener( e ->
{
new Thread( () -> {
OpenMoBIEProjectCommand openMoBIE = new OpenMoBIEProjectCommand();
openMoBIE.projectLocation = this.projectCreator.getProjectLocation().getAbsolutePath();
openMoBIE.projectLocation = new File( this.projectCreator.getProjectLocation().getAbsolutePath() );
openMoBIE.run();
} ).start();
} );
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/embl/mobie/lib/files/ImageFileSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.imglib2.Volatile;
import net.imglib2.realtransform.AffineTransform3D;
import org.apache.commons.io.FilenameUtils;
import org.embl.mobie.DataStore;
import org.embl.mobie.MoBIE;
import org.embl.mobie.io.ImageDataOpener;
import org.embl.mobie.io.imagedata.ImageData;
Expand All @@ -51,6 +52,7 @@
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;

import javax.xml.crypto.Data;
import java.io.File;
import java.util.*;

Expand Down Expand Up @@ -180,17 +182,19 @@ protected static boolean isCellProfilerColumn( String column, Table table )
private void setMetadata( Integer channelIndex )
{
metadataSource = nameToFullPath.keySet().iterator().next();
IJ.log( "Fetching metadata from " + nameToFullPath.get( metadataSource ) );
IJ.log( "Fetching metadata for channel " + channelIndex + "..." );
IJ.log( "...from image file " + nameToFullPath.get( metadataSource ) );
// FIXME: Cache the image data, because for multiple images it is now reloaded!
ImageData< ? > imageData = ImageDataOpener.open( nameToFullPath.get( metadataSource ) );
CanonicalDatasetMetadata canonicalDatasetMetadata = imageData.getMetadata( channelIndex );
metadata = new Metadata( canonicalDatasetMetadata );
Source< ? > source = imageData.getSourcePair( channelIndex ).getA();
metadata.numZSlices = (int) source.getSource( 0, 0 ).dimension( 2 );
metadata.numTimePoints = SourceHelper.getNumTimePoints( source );
metadata.contrastLimits = MoBIEHelper.computeMinMax( ( RandomAccessibleInterval ) source.getSource( 0, source.getNumMipmapLevels() -1 ) );
metadata.contrastLimits = MoBIEHelper.estimateMinMax( ( RandomAccessibleInterval ) source.getSource( 0, source.getNumMipmapLevels() -1 ) );
IJ.log( "Slices: " + metadata.numZSlices );
IJ.log( "Frames: " + metadata.numTimePoints );
IJ.log( "Min, max: " + Arrays.toString( metadata.contrastLimits ) );
IJ.log( "Contrast limits: " + Arrays.toString( metadata.contrastLimits ) );
}

private static String applyPathMapping( String pathMapping, String path )
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/embl/mobie/lib/source/SourceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@
import bdv.viewer.Source;
import mpicbg.spim.data.sequence.FinalVoxelDimensions;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.FinalRealInterval;
import net.imglib2.Interval;
import net.imglib2.Point;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealInterval;
import net.imglib2.RealPoint;
import net.imglib2.*;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.roi.RealMaskRealInterval;
import net.imglib2.roi.geom.GeomMasks;
import net.imglib2.roi.geom.real.WritableBox;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Intervals;
import net.imglib2.util.ValuePair;
import net.imglib2.view.Views;
import org.embl.mobie.lib.bdv.CalibratedMousePositionProvider;
import org.jetbrains.annotations.NotNull;
import sc.fiji.bdvpg.sourceandconverter.SourceAndConverterHelper;

import java.lang.reflect.Field;
import java.util.*;
Expand All @@ -60,7 +59,6 @@

public abstract class SourceHelper
{

public static < T > T unwrapSource( Source source, Class< T > clazz )
{
if ( source == null )
Expand Down Expand Up @@ -375,4 +373,5 @@ public static boolean isPositionWithinSourceInterval( Source< ? > source, RealPo
// }
// else {
}

}
16 changes: 14 additions & 2 deletions src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
import de.embl.cba.tables.SwingUtils;
import ij.IJ;
import ij.gui.GenericDialog;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.converter.Converter;
import net.imglib2.display.ColorConverter;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.ARGBType;
import org.embl.mobie.command.context.ConfigureSegmentRenderingCommand;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.MoBIE;
import org.embl.mobie.lib.MoBIEHelper;
import org.embl.mobie.lib.io.FileLocation;
import org.embl.mobie.lib.MoBIEInfo;
import org.embl.mobie.lib.Services;
Expand Down Expand Up @@ -488,7 +490,6 @@ public static JFrame showOpacityAndContrastLimitsDialog(
selection.setUpdateListener( opacityUpdateListener );
panel.add( opacitySlider );


if ( addContrastLimitUI )
{
// Contrast Limits
Expand All @@ -503,7 +504,6 @@ public static JFrame showOpacityAndContrastLimitsDialog(
.map( sac -> sac.getConverter() )
.collect( Collectors.toList() );


final double currentContrastLimitsMin = converterSetups.get( 0 ).getDisplayRangeMin();
final double currentContrastLimitsMax = converterSetups.get( 0 ).getDisplayRangeMax();
final double absCurrentRange = Math.abs( currentContrastLimitsMax - currentContrastLimitsMin );
Expand Down Expand Up @@ -548,6 +548,18 @@ public static JFrame showOpacityAndContrastLimitsDialog(
panel.add( minSlider );
panel.add( maxSlider );

JButton autoButton = new JButton("Auto Min Max");
autoButton.addActionListener( e ->
{
Source< ? > source = sacs.get( 0 ).getSpimSource();
RandomAccessibleInterval< ? > rai = source.getSource( bdvHandle.getViewerPanel().state().getCurrentTimepoint(),
source.getNumMipmapLevels() - 1 );
double[] minMax = MoBIEHelper.estimateMinMax( ( RandomAccessibleInterval ) rai );
min.setCurrentValue( minMax[ 0 ] );
max.setCurrentValue( minMax[ 1 ] );
});
panel.add( autoButton );

boolean isInvert = false;
for ( Converter< ?, ARGBType > converter : converters )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,37 @@ public static void main( String[] args )
final ImageJ imageJ = new ImageJ();
imageJ.ui().showUI();

// OpenTableCommand command = new OpenTableCommand();
// command.table = new File( "/Users/tischer/Desktop/teresa/summary_calculated1_subset.txt" );
// command.root = command.table.getParentFile();
// command.images = "FileName_Result.Image_IMG"; // Result.Image.Zarr
// command.gridType = GridType.Transformed; // TODO: not working with Stitched!
// command.run();

OpenTableCommand command = new OpenTableCommand();
//command.table = new File( "/Volumes/almf/group/Aliaksandr/User_data/Furlong_CrispR/test_data_20231018/20231004/20231004-172458/summary_calculated1.txt" );
//command.table = new File( "/Volumes/almf/group/Aliaksandr/User_data/Furlong_CrispR/test_data_20231018/20231004/20231004-172458/summary_calculated1_subset.txt" );
command.table = new File( "/Users/tischer/Desktop/teresa/summary_calculated1_subset.txt" );
//command.table = new File( "/Volumes/cba/exchange/furlong_test/summary_calculated1_subset_zarr.txt" );
//command.images = "Result.Image.Zarr"; // Result.Image.Zarr
command.table = new File( "/Volumes/CRISPR_project_data/test_data_new/20231122-170451/summary_new.txt" );
command.root = command.table.getParentFile();
command.images = "FileName_Result.Image_IMG"; // Result.Image.Zarr
command.images = "FileName_Result.Image_IMG";
command.gridType = GridType.Transformed; // TODO: not working with Stitched!
command.run();

/*
TODO:
Why is it fetching so much metadata?? It is opening the same data again for all channels.
Also initialisation is slow...
Min, max: [6.0, 2608.0]
Fetching metadata from /Volumes/CRISPR_project_data/test_data_new/20231122-170451/Result-Image/Result-Image--WA01--P0001--T0001.oir
Slices: 11
Frames: 1
Min, max: [13.0, 981.0]
Fetching metadata from /Volumes/CRISPR_project_data/test_data_new/20231122-170451/Result-Image/Result-Image--WA01--P0001--T0001.oir
Slices: 11
Frames: 1
Min, max: [7.0, 2060.0]
*/

}
}
Loading

0 comments on commit 0d87181

Please sign in to comment.