Skip to content

Commit

Permalink
Fix several issues concerning the transformation and image info loggi…
Browse files Browse the repository at this point in the history
…ng of AnnotationLabelImages
  • Loading branch information
tischi committed Nov 3, 2024
1 parent a0f972b commit 5d95fac
Show file tree
Hide file tree
Showing 39 changed files with 927 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.imglib2.realtransform.AffineTransform3D;
import org.embl.mobie.DataStore;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.image.RegionAnnotationImage;
import org.embl.mobie.lib.util.MoBIEHelper;
import org.embl.mobie.lib.image.Image;
import org.embl.mobie.lib.io.ImageDataInfo;
Expand Down Expand Up @@ -69,11 +70,14 @@ public void run()
visibleSacs.forEach( sac ->
{
Image< ? > image = DataStore.sourceToImage().get( sac );
if ( image instanceof RegionAnnotationImage )
return;

ImageDataInfo imageDataInfo = MoBIEHelper.fetchImageDataInfo( image );

Source< ? > source = sac.getSpimSource();
AffineTransform3D transform3D = new AffineTransform3D();
sac.getSpimSource().getSourceTransform( t, 0, transform3D );
AffineTransform3D sourceTransform = new AffineTransform3D();
sac.getSpimSource().getSourceTransform( t, 0, sourceTransform );

IJ.log( "" );
IJ.log( "# " + source.getName() );
Expand All @@ -88,11 +92,11 @@ public void run()
Transformation imageTransformation = transformations.get( 0 );
if ( imageTransformation instanceof AffineTransformation )
{
AffineTransform3D imageTransform = ( ( AffineTransformation ) imageTransformation ).getAffineTransform3D();
IJ.log( "Original image transformation: " + MoBIEHelper.print( imageTransform.getRowPackedCopy(), 3 ) );
AffineTransform3D additionalTransform = transform3D.copy().concatenate( imageTransform.inverse() );
IJ.log( "Additional MoBIE transformation: " + MoBIEHelper.print( additionalTransform.getRowPackedCopy(), 3 ) );
IJ.log( "Total transformation: " + MoBIEHelper.print( transform3D.getRowPackedCopy(), 3 ) );
AffineTransform3D initialTransform = ( ( AffineTransformation ) imageTransformation ).getAffineTransform3D();
IJ.log( "Original image transformation: " + MoBIEHelper.print( initialTransform.getRowPackedCopy(), 3 ) );
AffineTransform3D additionalTransform = sourceTransform.copy().concatenate( initialTransform.inverse() );
IJ.log( "Combined additional transformation: " + MoBIEHelper.print( additionalTransform.getRowPackedCopy(), 3 ) );
IJ.log( "Total transformation: " + MoBIEHelper.print( sourceTransform.getRowPackedCopy(), 3 ) );
}

if ( showTransformationHistory )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.io.IOException;


@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN_PROJECT + "Open PlatyBrowser")
@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN + "Open PlatyBrowser")
public class OpenPlatyBrowserCommand implements Command
{
static { net.imagej.patcher.LegacyInjector.preinit(); }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*-
* #%L
* Fiji viewer for MoBIE projects
* %%
* Copyright (C) 2018 - 2024 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.open.special;

import loci.common.DebugTools;
import net.imagej.ImageJ;
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.command.SpatialCalibration;
import org.embl.mobie.command.open.OpenCollectionTableCommand;
import org.embl.mobie.lib.transform.GridType;
import org.embl.mobie.ui.UserInterfaceHelper;
import org.jboss.netty.channel.UpstreamMessageEvent;
import org.scijava.ItemVisibility;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN + "Open OpenOrganelle" )
public class OpenOpenOrganelleDataCommand implements Command {

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

@Override
public void run()
{
final URL resource = OpenOpenOrganelleDataCommand.class.getResource( "/open-organelle.txt" );
String file = resource.getFile();
OpenCollectionTableCommand command = new OpenCollectionTableCommand();
command.table = new File( file );
command.run();
}

public static void main( String[] args )
{
// to update the table use org.embl.mobie.lib.util.OpenOrganelleCollectionTableCreator

new ImageJ().ui().showUI();
new OpenOpenOrganelleDataCommand().run();

// TODO
// - [X] The grid overlay boundaries are too thick for some reason
// - [X] Auto-contrast in a Transformed Grid View should be determined from an image that is currently visible!
// - [ ] Auto-contrast in the beginning of a grid view display would be nice
// - [X] For each RegionDisplay automatically overlay the region_id as an annotation
// - [X] The grids should not be exclusive in this case
// - [X] The EM should show first
// - [ ] How to implement one Grid and RegionDisplay for many sources?
// - how to deal with the fact that then there are multiple table rows for each region?
// - [ ] It would be cleaner if all the layers would be part of the same grid
// - this could be achieved by adding a "grid_position" column
// - but then we would also need a "display" column to sort the entries into the respective displays
// - an issue with this would be how to implement the region display, because s.a.
// - [X] Zoom to region when clicking on a RegionTable row
// - [ ] Yannick: exclusive column
// - [ ] John: Membrane segmentation pixel shit in jrc_jurkat-1/labels/pm_seg

}
}
22 changes: 9 additions & 13 deletions src/main/java/org/embl/mobie/lib/annotation/AnnotationUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
package org.embl.mobie.lib.annotation;

import de.embl.cba.tables.Logger;
import de.embl.cba.tables.SwingUtils;
import ij.IJ;
import net.imglib2.type.numeric.ARGBType;
import org.embl.mobie.lib.color.CategoricalAnnotationColoringModel;
Expand All @@ -40,16 +39,13 @@
import org.embl.mobie.lib.table.AnnotationTableModel;
import org.embl.mobie.lib.table.DefaultValues;
import org.embl.mobie.ui.MoBIELaf;
import org.embl.mobie.ui.SwingHelper;

import javax.swing.*;
import javax.swing.table.TableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.embl.mobie.lib.color.lut.LUTs.DARK_GREY;
Expand Down Expand Up @@ -166,7 +162,7 @@ private void showFrame()

private void addCreateCategoryButton()
{
final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();
final JButton button = new JButton( "Create new category" );
final JTextField textField = new JTextField( "nice_cell" );
panel.add( button );
Expand All @@ -190,7 +186,7 @@ private void addAnnotationButtons()
annotationButtonsPanel.setBorder( BorderFactory.createEmptyBorder(0,10,10,10) );
panel.add( annotationButtonsPanel );

final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();
panel.add( new JLabel( "Annotate selected " + objectName + "(s) as:" ) );
panel.add( new JLabel( " " ) );
annotationButtonsPanel.add( panel );
Expand Down Expand Up @@ -219,7 +215,7 @@ private void addAnnotationButtonPanel( String annotationName, A annotation )

annotationNames.add( annotationName );

final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();
final JButton annotateButton = new JButton( String.format("%1$15s", annotationName) );
annotateButton.setFont( new Font("monospaced", Font.PLAIN, 12) );
annotateButton.setOpaque( true );
Expand Down Expand Up @@ -271,7 +267,7 @@ private void addAnnotationButtonPanel( String annotationName, A annotation )

private void addSelectPreviousAndNextPanel( )
{
final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();
final JButton clear = createClearSelectionButton();
final JButton previous = createSelectPreviousButton();
final JButton next = createSelectNextButton();
Expand All @@ -283,7 +279,7 @@ private void addSelectPreviousAndNextPanel( )

private void addSelectIDPanel( )
{
final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();
final JButton button = createSelectButton();
selectAnnotationTextField = new JTextField( "" );
selectAnnotationTextField.setText( "1" );
Expand Down Expand Up @@ -463,7 +459,7 @@ private void selectRow( A row )

private void addSkipNonePanel( )
{
final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();

final JCheckBox checkBox = new JCheckBox( "Skip \"None\" & \"NaN\"" );
checkBox.setSelected( false );
Expand All @@ -479,7 +475,7 @@ private void addSkipNonePanel( )

private void addKeepSelectedPanel( )
{
final JPanel panel = SwingUtils.horizontalLayoutPanel();
final JPanel panel = SwingHelper.horizontalBoxLayoutPanel();

final JCheckBox checkBox = new JCheckBox( "Keep "+ objectName +"(s) selected after assignment" );
checkBox.setSelected( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ public double[] computeMinMax()
{
double viewerVoxelSpacing = BdvHandleHelper.getViewerVoxelSpacing( bdvHandle );
ScreenShotMaker screenShotMaker = new ScreenShotMaker( bdvHandle, "" );
screenShotMaker.run( Collections.singletonList( sourceAndConverter ), 4 * viewerVoxelSpacing );
screenShotMaker.run(
Collections.singletonList( sourceAndConverter ),
16 * viewerVoxelSpacing // times 16 to make it faster
);
ImagePlus imagePlus = screenShotMaker.getCompositeImagePlus();
Roi[] rois = screenShotMaker.getMasks();
if ( rois != null && rois.length > 0 )
imagePlus.setRoi( rois[ 0 ] );
IJ.run( imagePlus, "Enhance Contrast", "saturated=0.35" );
IJ.run( imagePlus, "Enhance Contrast", "saturated=0.03" );
// imagePlus.show();
double[] minMax = { imagePlus.getDisplayRangeMin(), imagePlus.getDisplayRangeMax() };
return minMax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public void close()
sliceViewer.getBdvHandle().getViewerPanel().requestRepaint();
}

@Override
public void setVisible( boolean visible )
{
overlaySource.setActive( visible );
}

@Override
protected synchronized void draw( Graphics2D g )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public void close()
sliceViewer.getBdvHandle().getViewerPanel().requestRepaint();
}

@Override
public void setVisible( boolean visible )
{
overlaySource.setActive( visible );
}

@Override
protected synchronized void draw( Graphics2D g )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public interface AnnotationOverlay
{
void close();

void setVisible( boolean visible );
}
43 changes: 34 additions & 9 deletions src/main/java/org/embl/mobie/lib/bdv/view/AnnotationSliceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
import bdv.viewer.Source;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.SynchronizedViewerState;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Volatile;
import net.imglib2.converter.Converter;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.roi.RealMaskRealInterval;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.util.LinAlgHelpers;
import org.embl.mobie.DataStore;
import org.embl.mobie.MoBIE;
import org.embl.mobie.lib.annotation.AnnotatedRegion;
import org.embl.mobie.lib.annotation.Annotation;
import org.embl.mobie.lib.annotation.SliceViewAnnotationSelector;
import org.embl.mobie.lib.color.AnnotationARGBConverter;
Expand All @@ -56,6 +60,8 @@
import org.embl.mobie.lib.source.BoundarySource;
import org.embl.mobie.lib.source.SourceHelper;
import org.embl.mobie.lib.source.VolatileBoundarySource;
import org.embl.mobie.lib.table.saw.TableSawAnnotatedImages;
import org.embl.mobie.lib.transform.viewer.MoBIEViewerTransformAdjuster;
import org.embl.mobie.lib.transform.viewer.ViewerTransformChanger;
import org.embl.mobie.lib.volume.SegmentVolumeViewer;
import sc.fiji.bdvpg.services.SourceAndConverterServices;
Expand Down Expand Up @@ -142,10 +148,17 @@ private void configureRendering( SourceAndConverter< ? > sourceAndConverter )
{
final String someRegion = display.sources.keySet().iterator().next();
final String someSource = display.sources.get( someRegion ).get( 0 );
final RealMaskRealInterval mask = DataStore.getImage( someSource ).getMask();
double width = mask.realMax( 0 ) - mask.realMin( 0 );
width = Math.min( width, mask.realMax( 1 ) - mask.realMin( 1 ) );
boundaryThickness = width * boundaryThickness;
Image< ? > image = DataStore.getImage( someSource );
final RealMaskRealInterval mask = image.getMask();
RandomAccessibleInterval< ? extends Volatile< ? > > source = image.getSourcePair().getVolatileSource().getSource( 0, 0 );
long[] dimensions = source.dimensionsAsLongArray();
double[] realDimensions = new double[3];
LinAlgHelpers.subtract( mask.maxAsDoubleArray(), mask.minAsDoubleArray(), realDimensions );
double minimalExtent = Double.MAX_VALUE;
for ( int d = 0; d < 3; d++ )
if ( dimensions[d] > 1 )
minimalExtent = Math.min( minimalExtent, realDimensions[d ] );
boundaryThickness = minimalExtent * boundaryThickness;
}
}
}
Expand Down Expand Up @@ -175,7 +188,7 @@ public void coloringChanged()
public synchronized void focusEvent( A selection, Object initiator )
{
if ( initiator instanceof SliceViewAnnotationSelector )
return;
return; // such that it is not focussed twice

final BdvHandle bdvHandle = getSliceViewer().getBdvHandle();
final SynchronizedViewerState state = bdvHandle.getViewerPanel().state();
Expand All @@ -184,11 +197,23 @@ public synchronized void focusEvent( A selection, Object initiator )
if ( timepoint != null )
state.setCurrentTimepoint( timepoint );

final double[] position = selection.positionAsDoubleArray();
if ( position != null )
new sc.fiji.bdvpg.bdv.navigate.ViewerTransformChanger(
AffineTransform3D viewerTransform;
if ( selection instanceof AnnotatedRegion )
{
RealMaskRealInterval mask = ( ( AnnotatedRegion ) selection ).getMask();
viewerTransform = MoBIEViewerTransformAdjuster.getViewerTransform( bdvHandle, mask );
}
else
{
final double[] position = selection.positionAsDoubleArray();
if ( position == null ) return;
viewerTransform = BdvPlaygroundHelper.getViewerTransformWithNewCenter( bdvHandle, position );

}

new sc.fiji.bdvpg.bdv.navigate.ViewerTransformChanger(
bdvHandle,
BdvPlaygroundHelper.getViewerTransformWithNewCenter( bdvHandle, position ),
viewerTransform,
false,
ViewerTransformChanger.animationDurationMillis ).run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
package org.embl.mobie.lib.create.ui;

import de.embl.cba.tables.SwingUtils;
import ij.IJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
Expand Down Expand Up @@ -327,7 +326,7 @@ private void addSeparatorToGrid( int rowIndex ) {
}

private void addButtonsPanel() {
final JPanel buttonsPanel = SwingUtils.horizontalLayoutPanel();
final JPanel buttonsPanel = SwingHelper.horizontalBoxLayoutPanel();

JButton remoteButton = new JButton("Add/update remote");
JButton openMoBIEButton = new JButton("Open in MoBIE");
Expand Down
Loading

0 comments on commit 5d95fac

Please sign in to comment.