Skip to content
Snippets Groups Projects
Commit caa8f5e4 authored by Jean-Yves Tinevez's avatar Jean-Yves Tinevez
Browse files

Region growing tool: use a coarser scale

parent d51cc5a1
No related branches found
No related tags found
No related merge requests found
......@@ -43,19 +43,29 @@ import viewer.render.SourceState;
import viewer.render.ViewerState;
import viewer.util.Affine3DHelpers;
public class Demo {
public class Demo
{
private LabelingSource< ? > overlay;
private LabelingSource overlay;
private final SpimViewer viewer;
private int nTimepoints;
private List< SourceAndConverter< ? >> sources;
private SetupAssignments setupAssignments;
private final BrightnessDialog brightnessDialog;
private boolean editMode = false;
private TransformEventHandler< AffineTransform3D > transformEventHandler;
private RegionGrowingAnnotationTool< ? > regionGrowingAnnotationTool;
public Demo(final File file) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException {
public Demo( final File file ) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException
{
/*
* Load image source
......@@ -75,48 +85,58 @@ public class Demo {
}
private void prepareSources(final File dataFile) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException {
@SuppressWarnings( { "rawtypes", "unchecked" } )
private void prepareSources( final File dataFile ) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException
{
final SequenceViewsLoader loader = new SequenceViewsLoader( dataFile.getAbsolutePath() );
final SequenceDescription seq = loader.getSequenceDescription();
nTimepoints = seq.numTimepoints();
sources = new ArrayList< SourceAndConverter< ? >>();
final ArrayList< ConverterSetup > converterSetups = new ArrayList< ConverterSetup >();
for (int setup = 0; setup < seq.numViewSetups(); ++setup) {
for ( int setup = 0; setup < seq.numViewSetups(); ++setup )
{
final RealARGBColorConverter< UnsignedShortType > converter = new RealARGBColorConverter< UnsignedShortType >( 0, 65535 );
converter.setColor( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
sources.add( new SourceAndConverter< UnsignedShortType >( new SpimSource( loader, setup, "angle " + seq.setups.get( setup ).getAngle() ), converter ) );
final int id = setup;
converterSetups.add(new ConverterSetup() {
converterSetups.add( new ConverterSetup()
{
@Override
public void setDisplayRange(final int min, final int max) {
public void setDisplayRange( final int min, final int max )
{
converter.setMin( min );
converter.setMax( max );
requestRepaintAllViewers();
}
@Override
public void setColor(final ARGBType color) {
public void setColor( final ARGBType color )
{
converter.setColor( color );
requestRepaintAllViewers();
}
@Override
public int getSetupId() {
public int getSetupId()
{
return id;
}
@Override
public int getDisplayRangeMin() {
public int getDisplayRangeMin()
{
return ( int ) converter.getMin();
}
@Override
public int getDisplayRangeMax() {
public int getDisplayRangeMax()
{
return ( int ) converter.getMax();
}
@Override
public ARGBType getColor() {
public ARGBType getColor()
{
return converter.getColor();
}
} );
......@@ -128,29 +148,35 @@ public class Demo {
setupAssignments = new SetupAssignments( converterSetups, 0, 65535 );
final MinMaxGroup group = setupAssignments.getMinMaxGroups().get( 0 );
for (final ConverterSetup setup : setupAssignments.getConverterSetups()) {
for ( final ConverterSetup setup : setupAssignments.getConverterSetups() )
{
setupAssignments.moveSetupToGroup( setup, group );
}
overlay = new LabelingSource(sources.get(0).getSpimSource());
// Use 2nd level
overlay = new LabelingSource( sources.get( 0 ).getSpimSource(), 2 );
sources.add( new SourceAndConverter< ARGBType >( overlay, new TypeIdentity< ARGBType >() ) );
}
private SpimViewer newViewer() {
private SpimViewer newViewer()
{
final SpimViewer viewer = new SpimViewer( 800, 600, sources, nTimepoints );
viewer.addKeyAction(KeyStroke.getKeyStroke("ESCAPE"), new AbstractAction("toggle mode") {
viewer.addKeyAction( KeyStroke.getKeyStroke( "ESCAPE" ), new AbstractAction( "toggle mode" )
{
@Override
public void actionPerformed(final ActionEvent arg0) {
public void actionPerformed( final ActionEvent arg0 )
{
toggleMode();
}
private static final long serialVersionUID = 1L;
} );
viewer.addKeyAction(KeyStroke.getKeyStroke("S"), new AbstractAction("brightness settings") {
viewer.addKeyAction( KeyStroke.getKeyStroke( "S" ), new AbstractAction( "brightness settings" )
{
@Override
public void actionPerformed(final ActionEvent arg0) {
public void actionPerformed( final ActionEvent arg0 )
{
toggleBrightnessDialog();
}
......@@ -161,17 +187,21 @@ public class Demo {
}
public void toggleBrightnessDialog() {
public void toggleBrightnessDialog()
{
brightnessDialog.setVisible( !brightnessDialog.isVisible() );
}
private void requestRepaintAllViewers() {
if (null != viewer) {
private void requestRepaintAllViewers()
{
if ( null != viewer )
{
viewer.requestRepaint();
}
}
private void initBrightness(final SpimViewer viewer, final double cumulativeMinCutoff, final double cumulativeMaxCutoff) {
private void initBrightness( final SpimViewer viewer, final double cumulativeMinCutoff, final double cumulativeMaxCutoff )
{
final ViewerState state = viewer.getState();
final Source< ? > source = state.getSources().get( state.getCurrentSource() ).getSpimSource();
@SuppressWarnings( { "rawtypes", "unchecked" } )
......@@ -184,12 +214,14 @@ public class Demo {
final long[] bin = new long[] { 0 };
double cumulative = 0;
int i = 0;
for (; i < numBins && cumulative < cumulativeMinCutoff; ++i) {
for ( ; i < numBins && cumulative < cumulativeMinCutoff; ++i )
{
bin[ 0 ] = i;
cumulative += dfd.relativeFrequency( bin );
}
final int min = i * 65535 / numBins;
for (; i < numBins && cumulative < cumulativeMaxCutoff; ++i) {
for ( ; i < numBins && cumulative < cumulativeMaxCutoff; ++i )
{
bin[ 0 ] = i;
cumulative += dfd.relativeFrequency( bin );
}
......@@ -199,7 +231,8 @@ public class Demo {
minmax.getMaxBoundedValue().setCurrentValue( max );
}
private void initTransform(final SpimViewer viewer, final int viewerWidth, final int viewerHeight) {
private void initTransform( final SpimViewer viewer, final int viewerWidth, final int viewerHeight )
{
final int cX = viewerWidth / 2;
final int cY = viewerHeight / 2;
......@@ -259,28 +292,36 @@ public class Demo {
}
@SuppressWarnings( { "rawtypes", "unchecked" } )
private void toggleMode() {
private void toggleMode()
{
this.editMode = !editMode;
System.out.println( editMode );// DEBUG
if (editMode) {
if ( editMode )
{
transformEventHandler = viewer.getDisplay().getTransformEventHandler();
viewer.getDisplay().removeHandler( transformEventHandler );
final int currentSource = viewer.getState().getCurrentSource();
final int timePoint = viewer.getState().getCurrentTimepoint();
regionGrowingAnnotationTool = new RegionGrowingAnnotationTool(viewer, sources.get(currentSource).getSpimSource(), overlay, timePoint);
regionGrowingAnnotationTool = new RegionGrowingAnnotationTool( viewer, overlay, timePoint );
viewer.getDisplay().addHandler( regionGrowingAnnotationTool );
} else {
}
else
{
viewer.getDisplay().removeHandler( regionGrowingAnnotationTool );
viewer.getDisplay().addHandler( transformEventHandler );
}
}
public static void main(final String[] args) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException {
public static void main( final String[] args ) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, JDOMException
{
ImageJ.main( args );
final File file = new File("/Users/tinevez/Desktop/Data/Mamut/parhyale-crop/parhyale-crop-2.xml");
// final File file = new File(
// "/Users/tinevez/Desktop/Data/Mamut/parhyale-crop/parhyale-crop-2.xml"
// );
final File file = new File( "E:/Users/JeanYves/Desktop/Data/Celegans.xml" );
new Demo( file );
}
......
......
......@@ -23,38 +23,49 @@ import net.imglib2.roi.IterableRegionOfInterest;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.IntType;
import viewer.SpimViewer;
import viewer.render.Source;
public class RegionGrowingAnnotationTool<T extends RealType<T>> implements MouseListener, MouseMotionListener {
public class RegionGrowingAnnotationTool< T extends RealType< T >> implements MouseListener, MouseMotionListener
{
private final SpimViewer viewer;
private Map< long[], Integer > seed;
private final LabelingSource labelingSource;
private final LabelingSource< T > labelingSource;
private int label = 0;
private final long[][] structuringElement;
private final GrowingMode growingMode;
private final NativeImgLabeling< Integer, IntType > labeling;
/**
* A {@link RandomAccess} to the source image.
*/
private final RandomAccess< T > ra;
/**
* The transform that maps source coordinates to mouse coordinates.
*/
private final AffineTransform3D sourceToGlobal;
public RegionGrowingAnnotationTool(final SpimViewer viewer, final Source<T> source, final LabelingSource labellingSource, final int t) {
public RegionGrowingAnnotationTool( final SpimViewer viewer, final LabelingSource< T > labelingSource, final int t )
{
this.viewer = viewer;
this.labelingSource = labellingSource;
this.labeling = labellingSource.getLabeling(t);
this.ra = source.getSource(t, 0).randomAccess();
this.sourceToGlobal = source.getSourceTransform(t, 0);
this.labelingSource = labelingSource;
this.labeling = labelingSource.getLabeling( t );
this.ra = labelingSource.getImgSource().getSource( t, labelingSource.getLevel() ).randomAccess();
this.sourceToGlobal = labelingSource.getImgSource().getSourceTransform( t, labelingSource.getLevel() );
this.structuringElement = AbstractRegionGrowing.get8ConStructuringElement( 3 );
this.growingMode = GrowingMode.SEQUENTIAL;
int freeLabel = 0;
for (final Integer existingLabel : labeling.getLabels()) {
if (existingLabel.intValue() > freeLabel) {
for ( final Integer existingLabel : labeling.getLabels() )
{
if ( existingLabel.intValue() > freeLabel )
{
freeLabel = existingLabel.intValue();
}
}
......@@ -62,47 +73,60 @@ public class RegionGrowingAnnotationTool<T extends RealType<T>> implements Mouse
}
@Override
public void mouseClicked(final MouseEvent e) {}
public void mouseClicked( final MouseEvent e )
{}
@Override
public void mouseEntered(final MouseEvent e) {}
public void mouseEntered( final MouseEvent e )
{}
@Override
public void mouseExited(final MouseEvent e) {}
public void mouseExited( final MouseEvent e )
{}
@Override
public void mousePressed(final MouseEvent e) {
public void mousePressed( final MouseEvent e )
{
final Point point = getLocationOnCurrentSource();
final long[] pos = new long[ 3 ];
point.localize( pos );
if (!labeling.getLabels().isEmpty()) {
if ( !labeling.getLabels().isEmpty() )
{
final RandomAccess< LabelingType< Integer >> randomAccess = labeling.randomAccess();
randomAccess.setPosition( point );
final List< Integer > existingLabels = randomAccess.get().getLabeling();
if (!existingLabels.isEmpty()) {
if ( !existingLabels.isEmpty() )
{
label = existingLabels.get(0).intValue(); // For future new annotation
label = existingLabels.get( 0 ).intValue(); // For future new
// annotation
for (final Integer existingLabel : existingLabels) {
for ( final Integer existingLabel : existingLabels )
{
final IterableRegionOfInterest roi = labeling.getIterableRegionOfInterest( existingLabel );
final IterableInterval< LabelingType< Integer >> overROI = roi.getIterableIntervalOverROI( labeling );
for (final LabelingType<Integer> labelingType : overROI) {
for ( final LabelingType< Integer > labelingType : overROI )
{
final ArrayList< Integer > labels = new ArrayList< Integer >( labelingType.getLabeling() );
labels.clear();
labelingType.setLabeling( labels );
}
}
} else {
}
else
{
label++;
}
} else {
}
else
{
label++;
}
......@@ -111,19 +135,23 @@ public class RegionGrowingAnnotationTool<T extends RealType<T>> implements Mouse
}
@Override
public void mouseReleased(final MouseEvent e) {}
public void mouseReleased( final MouseEvent e )
{}
@Override
public void mouseDragged(final MouseEvent arg0) {
public void mouseDragged( final MouseEvent arg0 )
{
/*
* Remove old stuff
*/
if (labeling.getLabels().contains(Integer.valueOf(label))) {
if ( labeling.getLabels().contains( Integer.valueOf( label ) ) )
{
final IterableRegionOfInterest iterableRegionOfInterest = labeling.getIterableRegionOfInterest( Integer.valueOf( label ) );
for (final LabelingType<Integer> ll : iterableRegionOfInterest.getIterableIntervalOverROI(labeling)) {
for ( final LabelingType< Integer > ll : iterableRegionOfInterest.getIterableIntervalOverROI( labeling ) )
{
final ArrayList< Integer > labels = new ArrayList< Integer >( ll.getLabeling() );
labels.remove( Integer.valueOf( label ) );
ll.setLabeling( labels );
......@@ -149,9 +177,11 @@ public class RegionGrowingAnnotationTool<T extends RealType<T>> implements Mouse
}
@Override
public void mouseMoved(final MouseEvent arg0) {}
public void mouseMoved( final MouseEvent arg0 )
{}
private Point getLocationOnCurrentSource() {
private Point getLocationOnCurrentSource()
{
final double[] coordinates = new double[ 3 ];
final RealPoint click = RealPoint.wrap( coordinates );
viewer.getGlobalMouseCoordinates( click );
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment