Skip to content

Commit

Permalink
Add ROIs to ScreenShotMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jan 5, 2024
1 parent 2d952a9 commit 4ceb546
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.gui.Roi;
import ij.plugin.filter.ThresholdToSelection;
import ij.process.ByteProcessor;
import ij.process.ImageConverter;
import ij.process.ImageProcessor;
import net.imglib2.realtransform.AffineTransform3D;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.MoBIEHelper;
Expand All @@ -51,6 +55,7 @@
import sc.fiji.bdvpg.bdv.BdvHandleHelper;
import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand;

import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand All @@ -75,9 +80,6 @@ public class AutomaticRegistrationCommand extends DynamicCommand implements BdvP
@Parameter(label="Registration Voxel Size", persist = false, min = "0.0", style="format:#.00000")
public Double voxelSize = 1D;

@Parameter(label="Out of Bounds Value")
public String outOfBoundsValue = "Do not use";

@Parameter ( label = "Transformation", choices = { TRANSLATION, RIGID, SIMILARITY, AFFINE } )
private String transformationType = TRANSLATION;

Expand Down Expand Up @@ -153,15 +155,7 @@ private void compute()
// create two 2D ImagePlus that are to be aligned
//
ScreenShotMaker screenShotMaker = new ScreenShotMaker( bdvHandle, sacA.getSpimSource().getVoxelDimensions().unit() );
try
{
// useful for images with bright background
// to avoid an edge with the black background of BDV
screenShotMaker.setOutOfBoundsValue( Float.parseFloat( this.outOfBoundsValue ) );
} catch ( Exception e )
{
// don't set an out-of-bounds value.
}

screenShotMaker.run( Arrays.asList( sacA, sacB ), voxelSize );
CompositeImage compositeImage = screenShotMaker.getCompositeImagePlus();
AffineTransform3D canvasToGlobalTransform = screenShotMaker.getCanvasToGlobalTransform();
Expand All @@ -170,16 +164,21 @@ private void compute()
ImagePlus impA = new ImagePlus( imageA + " (fixed)", stack.getProcessor( 1 ) );
ImagePlus impB = new ImagePlus( imageB + " (moving)", stack.getProcessor( 2 ) );

// set the display ranges and burn them in by converting to unit8
// set the display ranges and burn them in by converting to uint8
// this is important for the intensity based registration methods
compositeImage.setPosition( 1 );
impA.getProcessor().setMinAndMax( compositeImage.getDisplayRangeMin(), compositeImage.getDisplayRangeMax() );
new ImageConverter( impA ).convertToGray8();

compositeImage.setPosition( 2 );
impB.getProcessor().setMinAndMax( compositeImage.getDisplayRangeMin(), compositeImage.getDisplayRangeMax() );
new ImageConverter( impA ).convertToGray8();
new ImageConverter( impB ).convertToGray8();
double min = impA.getProcessor().getMax();
double max = impA.getProcessor().getMax();

// set the rois within which the images contain valid pixel values
// those are used by some registration methods, e.g. turboReg
Roi[] rois = screenShotMaker.getMasks();
impA.setRoi( rois[ 0 ] );
impB.setRoi( rois[ 1 ] );

// compute the transformation that aligns the two images in 2D
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import bdv.util.BdvHandle;
import ij.IJ;
import ij.gui.Roi;
import ij.plugin.frame.RoiManager;
import org.embl.mobie.MoBIE;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.bdv.ScreenShotMaker;
Expand Down Expand Up @@ -63,13 +65,13 @@ public class ScreenShotMakerCommand extends DynamicCommand implements BdvPlaygro
@Override
public void run()
{
if ( MoBIE.getInstance().getSettings().values.isOpenedFromCLI() )
MoBIE.imageJ.ui().showUI();

ScreenShotMaker screenShotMaker = new ScreenShotMaker( bdvHandle, pixelUnit );
screenShotMaker.run( targetSamplingInXY );
screenShotMaker.getRGBImagePlus().show();
screenShotMaker.getCompositeImagePlus().show();

if ( MoBIE.getInstance().getSettings().values.isOpenedFromCLI() )
MoBIE.imageJ.ui().showUI();
}

@Override
Expand Down Expand Up @@ -99,7 +101,5 @@ private void showNumPixels()
{
final long[] sizeInPixels = ScreenShotMaker.getCaptureImageSizeInPixels( bdvHandle, targetSamplingInXY );
IJ.log( CAPTURE_SIZE_PIXELS + Arrays.toString( sizeInPixels ) );
// final MutableModuleItem< String > message = getInfo().getMutableInput("message", String.class);
// message.setValue( this, CAPTURE_SIZE_PIXELS + sizeInPixels[ 0 ] + ", " + sizeInPixels[ 1 ] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ else if ( mode.equals( AdditionMode.Concatenate ) )
}
}

public static double[] parseStringToDoubleArray(String arrayStr) {
arrayStr = arrayStr.replaceAll("[^0-9.,]", "");
public static double[] parseStringToDoubleArray(String arrayStr)
{
arrayStr = arrayStr.replaceAll("\\[|\\]", "");
String[] items = arrayStr.split(",\\s*");
double[] doubles = Arrays.stream(items).mapToDouble(Double::parseDouble).toArray();
return doubles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import java.util.Optional;
import java.util.Set;

@Plugin(type = BdvPlaygroundActionCommand.class, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + "Show " + ShowRasterImagesCommand.RAW + " Image(s)" )
@Plugin(type = BdvPlaygroundActionCommand.class, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + "Show " + ShowRasterImagesCommand.RAW + " Images" )
public class ShowRasterImagesCommand< T extends NumericType< T > > implements BdvPlaygroundActionCommand
{
static { net.imagej.patcher.LegacyInjector.preinit(); }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class SourcesInfoCommand implements BdvPlaygroundActionCommand
{
static { net.imagej.patcher.LegacyInjector.preinit(); }

public static final String CAPTURE_SIZE_PIXELS = "Capture size [pixels]: ";

@Parameter
public BdvHandle bdvHandle;

Expand All @@ -68,16 +66,18 @@ public void run()
{
Source< ? > source = sac.getSpimSource();
IJ.log( "# " + source.getName() );
IJ.log( "Data type: " + source.getType().getClass() );
IJ.log( "Shape: " + Arrays.toString( source.getSource( 0,0 ).dimensionsAsLongArray() ) );
IJ.log( "Number of resolution levels: " + source.getNumMipmapLevels() );
IJ.log( "Voxel size: " + Arrays.toString( source.getVoxelDimensions().dimensionsAsDoubleArray() ) );

if ( source instanceof TransformedSource )
{
AffineTransform3D transform3D = new AffineTransform3D();
( ( TransformedSource<?> ) source ).getFixedTransform( transform3D );
IJ.log( "Additional transform: " + transform3D );
IJ.log( "Additional transform:\n" + Arrays.toString( transform3D.getRowPackedCopy() ) );
source.getSourceTransform( 0, 0, transform3D );
IJ.log( "Full transform: " + transform3D );
IJ.log( "Full transform:\n" + Arrays.toString( transform3D.getRowPackedCopy() ) );
}
});
}
Expand Down
Loading

0 comments on commit 4ceb546

Please sign in to comment.