Skip to content

Commit

Permalink
Do not pre-compute contrast limits for sources that are too large, an…
Browse files Browse the repository at this point in the history
…d remove auto contrast button
  • Loading branch information
tischi committed Jul 4, 2024
1 parent dbbf978 commit 168ddb6
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public MoBIE( String tablePath, MoBIESettings settings, boolean isCollectionTabl

CollectionTableDataSetter dataSetter = new CollectionTableDataSetter( table );
dataSetter.addToDataset( dataset );
dataset.is2D(false); // TODO: determine from data?

initUiAndShowView( dataset.views().values().iterator().next().getName() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@ protected void applyTransform( AffineTransform3D affineTransform3D )
// applyTransformInPlace( affineTransform3D );
}

createAndSaveAffineTransformedImages( movingImages, affineTransform3D, suffix );
createSaveAndViewAffineTransformedImages( movingImages, affineTransform3D, suffix );

// TODO close the Command UI, HOW?
// https://imagesc.zulipchat.com/#narrow/stream/327238-Fiji/topic/Close.20Scijava.20Command.20UI


// FIXME close the Command UI, HOW?
// Maybe we use the hack that finds the awt Window based on its name?
// https://imagesc.zulipchat.com/#narrow/stream/327238-Fiji/topic/Close.20Scijava.20Command.20UI
}

protected static void createAndSaveAffineTransformedImages(
protected static void createSaveAndViewAffineTransformedImages(
Collection< Image< ? > > movingImages,
AffineTransform3D affineTransform3D,
String suffix )
Expand All @@ -160,6 +163,8 @@ protected static void createAndSaveAffineTransformedImages(

if ( MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view ) )
{
// Show the transformed images
// TODO: it would be nice to remove the non-transformed images from the current view
MoBIE.getInstance().getViewManager().show( view );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ private void acceptManualTransform()
// And this new transformed image will also be shown by the above applyTransform function.
transformationEditor.setActive( false );

getInfo().getMutableInput( "status", String.class )
.setValue( this, INACTIVE );
getInfo().getMutableInput( "status", String.class ).setValue( this, INACTIVE );

// TODO: make the non-transformed sources invisible

// TODO: Close the Command UI, but how?
// https://imagesc.zulipchat.com/#narrow/stream/327238-Fiji/topic/Close.20Scijava.20Command.20UI
}

private void cancelManualTransform()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.embl.mobie.lib.data;

import ij.IJ;
import ij.ImagePlus;
import net.imglib2.type.numeric.ARGBType;
import org.apache.commons.io.FilenameUtils;
import org.embl.mobie.io.ImageDataFormat;
import org.embl.mobie.io.imagedata.TIFFImageData;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.lib.color.ColorHelper;
import org.embl.mobie.lib.io.StorageLocation;
Expand Down Expand Up @@ -48,6 +50,9 @@ public void addToDataset( Dataset dataset )
final StorageLocation storageLocation = new StorageLocation();
storageLocation.absolutePath = getUri( row );
ImageDataFormat imageDataFormat = ImageDataFormat.fromPath( storageLocation.absolutePath );
// FIXME: how to decide?
// for big TIFF images we should use BioFormats...
//imageDataFormat = ImageDataFormat.BioFormats;
storageLocation.setChannel( getChannel( row ) ); // TODO: Fetch from table or URI? https://forum.image.sc/t/loading-only-one-channel-from-an-ome-zarr/97798
String imageName = getName( row );
String pixelType = getPixelType( row );
Expand Down Expand Up @@ -81,11 +86,10 @@ public void addToDataset( Dataset dataset )

addDisplayToViews( dataset, display, row );

// IJ.log("## " + imageName );
// IJ.log("URI: " + storageLocation.absolutePath );
// IJ.log("Format: " + imageDataFormat );
// IJ.log("Type: " + pixelType );

IJ.log("## " + imageName );
IJ.log("URI: " + storageLocation.absolutePath );
IJ.log("Opener: " + imageDataFormat );
IJ.log("Type: " + pixelType );
}
}

Expand Down Expand Up @@ -231,10 +235,10 @@ private static List< Transformation > getTransforms( String imageName, Row row )
{
String string = row.getString( CollectionTableConstants.AFFINE );
string = string.replace("(", "").replace(")", "");
String[] strings = string.split(", ");
String[] strings = string.split(",");
double[] doubles = new double[strings.length];
for (int i = 0; i < strings.length; i++) {
doubles[i] = Double.parseDouble(strings[i]);
doubles[i] = Double.parseDouble(strings[i].trim());
}

AffineTransformation affine = new AffineTransformation(
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/org/embl/mobie/lib/data/ImageGridSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import ij.IJ;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.util.Intervals;
import org.apache.commons.io.FilenameUtils;
import org.embl.mobie.io.ImageDataOpener;
import org.embl.mobie.io.imagedata.ImageData;
Expand Down Expand Up @@ -176,6 +177,7 @@ protected static boolean isCellProfilerColumn( String column, Table table )

private void setMetadata( Integer channelIndex )
{
// Take the first source to fetch metadata
metadataSource = nameToFullPath.keySet().iterator().next();
IJ.log( "Fetching metadata for channel " + channelIndex + "..." );
IJ.log( "...from image file " + nameToFullPath.get( metadataSource ) );
Expand All @@ -184,12 +186,24 @@ private void setMetadata( Integer channelIndex )
CanonicalDatasetMetadata canonicalDatasetMetadata = imageData.getMetadata( channelIndex );
metadata = new Metadata( canonicalDatasetMetadata );
Source< ? > source = imageData.getSourcePair( channelIndex ).getA();
metadata.numZSlices = (int) source.getSource( 0, 0 ).dimension( 2 );
RandomAccessibleInterval< ? > highResRAI = source.getSource( 0, 0 );
metadata.numZSlices = (int) highResRAI.dimension( 2 );
metadata.numTimePoints = SourceHelper.getNumTimePoints( source );
metadata.contrastLimits = SourceHelper.estimateMinMax( ( RandomAccessibleInterval ) source.getSource( 0, source.getNumMipmapLevels() -1 ) );
IJ.log( "Slices: " + metadata.numZSlices );
IJ.log( "Frames: " + metadata.numTimePoints );
IJ.log( "Contrast limits: " + Arrays.toString( metadata.contrastLimits ) );

// determine contrast limits if affordable
RandomAccessibleInterval< ? > lowResRAI = source.getSource( 0, source.getNumMipmapLevels() - 1 );
long numElements = Intervals.numElements( lowResRAI.dimensionsAsLongArray() );
if ( numElements < 1024 * 1024 )
{
IJ.log( "Contrast limits: " + Arrays.toString( metadata.contrastLimits ) );
metadata.contrastLimits = SourceHelper.estimateMinMax( ( RandomAccessibleInterval ) lowResRAI );
}
else
{
IJ.log( "Contrast limits: Not determined, as image is too large" );
}
}

private static String applyPathMapping( String pathMapping, String path )
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +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 = SourceHelper.estimateMinMax( ( RandomAccessibleInterval ) rai );
min.setCurrentValue( minMax[ 0 ] );
max.setCurrentValue( minMax[ 1 ] );
});
panel.add( autoButton );
// FIXME: This hangs for large sources without resolution pyramid
// 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 = SourceHelper.estimateMinMax( ( RandomAccessibleInterval ) rai );
// min.setCurrentValue( minMax[ 0 ] );
// max.setCurrentValue( minMax[ 1 ] );
// });
// panel.add( autoButton );

boolean isInvert = false;
for ( Converter< ?, ARGBType > converter : converters )
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/debug/DebugIssue1167.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package debug;

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

import java.io.File;

public class DebugIssue1167
{
public static void main( String[] args )
{
new ImageJ().ui().showUI();
final OpenImageAndLabelsCommand command = new OpenImageAndLabelsCommand();
command.image = new File( "/Users/tischer/Desktop/tim-oliver.ome.zarr" );
command.run();
}
}
48 changes: 48 additions & 0 deletions src/test/java/develop/DynamicDialogExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package develop;

import bdv.tools.boundingbox.TransformedBoxEditor;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class DynamicDialogExample {
public static void main(String[] args) {
// Create the frame
JFrame frame = new JFrame("Conditional TextField Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setLayout(new FlowLayout());

// Create the combo box (choice)
String[] choices = {"Select an option", "Show TextField", "Other"};
JComboBox<String> comboBox = new JComboBox<>(choices);
frame.add(comboBox);

// Create the text field
JTextField textField = new JTextField(15);
textField.setVisible(false); // Initially hidden
frame.add(textField);

// Add item listener to the combo box
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
String selectedItem = (String) comboBox.getSelectedItem();
if ("Show TextField".equals(selectedItem)) {
textField.setVisible(true);
} else {
textField.setVisible(false);
}
frame.revalidate();
frame.repaint();
}
}
});

// Display the frame
frame.setVisible(true);
}
}
22 changes: 22 additions & 0 deletions src/test/java/develop/OpenPaoloFirstTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package develop;

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

import java.io.File;

public class OpenPaoloFirstTable
{
public static void main( String[] args )
{
final ImageJ imageJ = new ImageJ();
imageJ.ui().showUI();

String tablePath = "/Users/tischer/Desktop/Paolo.txt";
File tableFile = new File( tablePath );

OpenCollectionTableCommand command = new OpenCollectionTableCommand();
command.table = tableFile;
command.run();
}
}
63 changes: 63 additions & 0 deletions src/test/java/develop/SimpleDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package develop;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SimpleDialog {
private JTextField textField;
private boolean isOkPressed;

public SimpleDialog() {
JDialog dialog = new JDialog((Frame) null, "Simple Dialog", true);
textField = new JTextField(20);
JPanel panel = new JPanel();
panel.add(new JLabel("Enter something:"));
panel.add(textField);
dialog.add(panel, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel();
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("Cancel");
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
dialog.add(buttonPanel, BorderLayout.SOUTH);

okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isOkPressed = true;
dialog.setVisible(false);
}
});

cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isOkPressed = false;
dialog.setVisible(false);
}
});

dialog.pack();
dialog.setVisible( true );
}

public boolean isOkPressed() {
return isOkPressed;
}

public String getInput() {
return textField.getText();
}

public static void main(String[] args) {

SimpleDialog dialog = new SimpleDialog();

if (dialog.isOkPressed()) {
System.out.println("User input: " + dialog.getInput());
} else {
System.out.println("User cancelled the input.");
}
}
}

0 comments on commit 168ddb6

Please sign in to comment.