Skip to content

Commit

Permalink
Add an option to capture overlay with a white background.
Browse files Browse the repository at this point in the history
Fix #274
  • Loading branch information
tinevez committed Aug 3, 2023
1 parent eb441ff commit 99ed09d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import ij.ImageStack;
import ij.measure.Calibration;
import ij.process.ColorProcessor;
import ij.process.ImageProcessor;

public class CaptureOverlayAction extends AbstractTMAction
{
Expand All @@ -63,12 +64,15 @@ public class CaptureOverlayAction extends AbstractTMAction
"Also, make sure nothing is moved over the image while capturing. " +
"</html>";


private static int firstFrame = -1;

private static int lastFrame = -1;

private static boolean hideImage = false;

private static boolean whiteBackground = false;

@Override
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame gui )
{
Expand All @@ -83,7 +87,7 @@ public void execute( final TrackMate trackmate, final SelectionModel selectionMo

if ( gui != null )
{
final CaptureOverlayPanel panel = new CaptureOverlayPanel( firstFrame, lastFrame, hideImage );
final CaptureOverlayPanel panel = new CaptureOverlayPanel( firstFrame, lastFrame, hideImage, whiteBackground );
final int userInput = JOptionPane.showConfirmDialog(
gui,
panel,
Expand All @@ -102,6 +106,7 @@ public void execute( final TrackMate trackmate, final SelectionModel selectionMo
firstFrame = Math.max( 1, firstFrame );
lastFrame = Math.min( imp.getNFrames(), lastFrame );
hideImage = panel.isHideImage();
whiteBackground = panel.isWhiteBackground();
}

if ( hideImage )
Expand All @@ -113,6 +118,14 @@ public void execute( final TrackMate trackmate, final SelectionModel selectionMo
imp.getNSlices(),
imp.getNFrames(),
TMUtils.getSpatialCalibration( imp ) );
if ( whiteBackground )
{
ImageProcessor ip = imp2.getProcessor();
ip.invertLut();
if ( imp2.getStackSize() > 1 )
imp2.getStack().setColorModel( ip.getColorModel() );
imp2.updateAndRepaintWindow();
}
// Add overlay to it.
final HyperStackDisplayer displayer = new HyperStackDisplayer( trackmate.getModel(), new SelectionModel( trackmate.getModel() ), imp2, displaySettings );
displayer.render();
Expand Down
53 changes: 42 additions & 11 deletions src/main/java/fiji/plugin/trackmate/action/CaptureOverlayPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ public class CaptureOverlayPanel extends JPanel

private boolean hideImage;

public CaptureOverlayPanel( final int firstFrame, final int lastFrame, final boolean hideImage )
private boolean whiteBackground;

public CaptureOverlayPanel( final int firstFrame, final int lastFrame, final boolean hideImage, boolean whiteBackground )
{
this.firstFrame = firstFrame;
this.lastFrame = lastFrame;
this.hideImage = hideImage;
this.whiteBackground = whiteBackground;

final GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[] { 0, 0, 0 };
gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 };
gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
gridBagLayout.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
setLayout( gridBagLayout );

final JLabel lblFirstFrame = new JLabel( "First frame:" );
Expand Down Expand Up @@ -96,13 +99,13 @@ public CaptureOverlayPanel( final int firstFrame, final int lastFrame, final boo
gbcTftLast.gridy = 1;
add( tftLast, gbcTftLast );

final JLabel lblNewLabel = new JLabel( "Hide image:" );
final GridBagConstraints gbcLblNewLabel = new GridBagConstraints();
gbcLblNewLabel.anchor = GridBagConstraints.EAST;
gbcLblNewLabel.insets = new Insets( 0, 0, 5, 5 );
gbcLblNewLabel.gridx = 0;
gbcLblNewLabel.gridy = 2;
add( lblNewLabel, gbcLblNewLabel );
final JLabel lblHideImage = new JLabel( "Hide image:" );
final GridBagConstraints gbcLblHideImage = new GridBagConstraints();
gbcLblHideImage.anchor = GridBagConstraints.EAST;
gbcLblHideImage.insets = new Insets( 0, 0, 5, 5 );
gbcLblHideImage.gridx = 0;
gbcLblHideImage.gridy = 2;
add( lblHideImage, gbcLblHideImage );

final JCheckBox chckbxHideImage = new JCheckBox();
chckbxHideImage.setSelected( hideImage );
Expand All @@ -113,6 +116,25 @@ public CaptureOverlayPanel( final int firstFrame, final int lastFrame, final boo
gbcChckbxHideImage.gridy = 2;
add( chckbxHideImage, gbcChckbxHideImage );

final JLabel lblWhiteBackground = new JLabel( "White background:" );
lblWhiteBackground.setEnabled( hideImage );
final GridBagConstraints gbcLblWhiteBackground = new GridBagConstraints();
gbcLblWhiteBackground.anchor = GridBagConstraints.EAST;
gbcLblWhiteBackground.insets = new Insets( 0, 0, 5, 5 );
gbcLblWhiteBackground.gridx = 0;
gbcLblWhiteBackground.gridy = 3;
add( lblWhiteBackground, gbcLblWhiteBackground );

final JCheckBox chckbxWhiteBackground = new JCheckBox();
chckbxWhiteBackground.setSelected( whiteBackground );
chckbxWhiteBackground.setEnabled( hideImage );
final GridBagConstraints gbcChckbxWhiteBackground = new GridBagConstraints();
gbcChckbxWhiteBackground.anchor = GridBagConstraints.WEST;
gbcChckbxWhiteBackground.insets = new Insets( 0, 0, 5, 0 );
gbcChckbxWhiteBackground.gridx = 1;
gbcChckbxWhiteBackground.gridy = 3;
add( chckbxWhiteBackground, gbcChckbxWhiteBackground );

final FocusListener fl = new FocusAdapter()
{
@Override
Expand All @@ -133,7 +155,12 @@ public void run()

tftFirst.addPropertyChangeListener( "value", ( e ) -> this.firstFrame = ( ( Number ) tftFirst.getValue() ).intValue() );
tftLast.addPropertyChangeListener( "value", ( e ) -> this.lastFrame = ( ( Number ) tftLast.getValue() ).intValue() );
chckbxHideImage.addActionListener( e -> this.hideImage = chckbxHideImage.isSelected() );
chckbxHideImage.addActionListener( e -> {
this.hideImage = chckbxHideImage.isSelected();
chckbxWhiteBackground.setEnabled( this.hideImage );
lblWhiteBackground.setEnabled( this.hideImage );
} );
chckbxWhiteBackground.addActionListener( e -> this.whiteBackground = chckbxWhiteBackground.isSelected() );
}

public int getFirstFrame()
Expand All @@ -151,4 +178,8 @@ public boolean isHideImage()
return hideImage;
}

public boolean isWhiteBackground()
{
return whiteBackground;
}
}

1 comment on commit 99ed09d

@imagesc-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/trackmate-overlay-background-color/83034/6

Please sign in to comment.