Skip to content

Commit

Permalink
Correct Macro recording - MotiQ Thresholder - issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenjn committed Jul 26, 2024
1 parent 936963c commit fb542d3
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Thresholder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<artifactId>MotiQ_Thresholder</artifactId>
<groupId>JNH</groupId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>

<!-- Plugin Information -->
<name>MotiQ thresholder</name>
Expand Down
119 changes: 113 additions & 6 deletions Thresholder/src/main/java/motiQ_thr/Thresholder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C) 2015-2024 Jan N. Hansen
* First version: January 05, 2015
* This version: July 25, 2024
* This version: July 26, 2024
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -37,13 +37,14 @@
import ij.measure.*;
import ij.process.*;
import ij.plugin.*;
import ij.plugin.frame.Recorder;
import ij.text.*;
import java.text.*;

public class Thresholder implements PlugIn, Measurements{//, DialogListener {
//Name variables
final static String PLUGINNAME = "MotiQ_thresholder";
final static String PLUGINVERSION = "v0.2.0";
final static String PLUGINVERSION = "v0.2.1";

//Fonts
static final Font SuperHeadingFont = new Font("Sansserif", Font.BOLD, 16);
Expand All @@ -56,6 +57,7 @@ public class Thresholder implements PlugIn, Measurements{//, DialogListener {
static final DecimalFormat dformat0 = new DecimalFormat("#0",new DecimalFormatSymbols(Locale.US));
static final DecimalFormat dformat1 = new DecimalFormat("#0.000000",new DecimalFormatSymbols(Locale.US));
static final DecimalFormat dformat2 = new DecimalFormat("#0.00",new DecimalFormatSymbols(Locale.US));
DecimalFormat dformatdialog = new DecimalFormat("#0.000000");

// final static String[] DSLItems = {"3D Analysis (CLSM, 2PM)", "2D in vivo / acute slices (live 2PM)", "2D in vitro (epiFM)"};

Expand Down Expand Up @@ -102,9 +104,12 @@ public class Thresholder implements PlugIn, Measurements{//, DialogListener {
//Multi-task management
ProgressDialog progressDialog;
boolean processingDone = false;
boolean continueProcessing = true;
boolean continueProcessing = true;

boolean record = false;

public void run(String arg) {
dformatdialog.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//-----------Eventually read settings from macro input------------------------
Expand Down Expand Up @@ -291,7 +296,13 @@ public void run(String arg) {
showDialog = false;
}

record = false;

if(showDialog) {
if(Recorder.record) {
record = true;
Recorder.record = false;
}
/**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *
* display dialog
* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */
Expand Down Expand Up @@ -365,9 +376,78 @@ public void run(String arg) {
autoSaveImage = gd.getNextBoolean();
saveDate = gd.getNextBoolean();

if (gd.wasCanceled()) return;
if (gd.wasCanceled()) return;

if(record) {
Recorder.record = true;
}
}

//Create macro recording string if macro recording activated:
if (record) {
String recordString = "";
if(useAlternateRef) {
recordString += "use-alternate ";

if(getImageByName) {
recordString += "automatically-find ";
}

recordString += "begin-of-suffix=[" + nameSuffix + "] ";

recordString += "additional-suffix=[" + parentEnding + "] ";

if(restrictToPos) {
recordString += "restrict ";
}
}

recordString += "scale=" + dformatdialog.format(scalingFactor) + " ";

if(conv8Bit) {
recordString += "convert ";
}

recordString += "threshold=" + selectedAlgorithm + " ";

recordString += "stack-handling=[" + chosenStackMethod + "] ";

if(separateFrames) {
recordString += "threshold-every-time-step ";
}

if(onlyTimeGroup) {
recordString += "threshold-only-distinct-times ";
recordString += "start-time=" + startGroup + " ";
recordString += "end-time=" + endGroup + " ";
}

if(localThreshold) {
recordString += "local-threshold ";
recordString += "local-threshold-radius=" + locThrRadius + " ";
}

if(fillHoles) {
recordString += "fill-holes ";
}

if(keepIntensities) {
recordString += "keep-intensities ";
}

if(autoSaveImage) {
recordString += "automatically-save ";
}

if(saveDate) {
recordString += "include-date ";
}

recordString = recordString.substring(0,recordString.length()-1);

Recorder.record = true;

Recorder.recordString("run(\"" + PLUGINNAME + " (" + PLUGINVERSION + ")\",\"" + recordString + "\");\n");
}

/**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Expand Down Expand Up @@ -492,6 +572,9 @@ public void windowClosing(WindowEvent winEvt) {
// progressDialog.setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
progressDialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent winEvt) {
if (record) {
Recorder.record = true;
}
if(processingDone==false){
IJ.error("Script stopped...");
}
Expand Down Expand Up @@ -1109,8 +1192,14 @@ else if(chosenStackMethod.equals(stackMethod[4])){
parImp.close();

if(keepIntensities == false){
if (record) {
Recorder.record = false;
}
IJ.run(imp, "Grays", "");
if(imp.getBitDepth() != 8) IJ.run(imp, "8-bit", "");
if (record) {
Recorder.record = true;
}
}

/***************************************************************************
Expand Down Expand Up @@ -1193,7 +1282,13 @@ else if(chosenStackMethod.equals(stackMethod[4])){
+ " but WITHOUT ANY WARRANTY; without even the implied warranty of"
+ " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
tw1.append("Plugin version: "+PLUGINVERSION);
if (record) {
Recorder.record = false;
}
tw1.saveAs(outputPath + "_log.txt");
if (record) {
Recorder.record = true;
}
}
//Save Image Treatment

Expand All @@ -1204,7 +1299,7 @@ else if(chosenStackMethod.equals(stackMethod[4])){
}
System.gc();
}
processingDone = true;
processingDone = true;
}


Expand Down Expand Up @@ -1506,13 +1601,20 @@ private void segmentImage(ImagePlus imp, double threshold, int z){
}
}
imp.setPosition(z+1);

if (record) {
Recorder.record = false;
}
if(!Prefs.blackBackground) {
IJ.run(maskImp, "Invert", "slice");
}
IJ.run(maskImp, "Fill Holes", "slice");
if(!Prefs.blackBackground) {
IJ.run(maskImp, "Invert", "slice");
}
if (record) {
Recorder.record = true;
}

progressDialog.updateBarText("segment image...");
for(int x = 0; x < imp.getWidth(); x++){
Expand Down Expand Up @@ -1563,7 +1665,9 @@ private void segmentImageLocally (ImagePlus imp, double thresholdMatrix [][][]){
}
}


if (record) {
Recorder.record = false;
}
if(!Prefs.blackBackground) {
IJ.run(transImp, "Invert", "stack");
}
Expand All @@ -1573,6 +1677,9 @@ private void segmentImageLocally (ImagePlus imp, double thresholdMatrix [][][]){
if(!Prefs.blackBackground) {
IJ.run(transImp, "Invert", "stack");
}
if (record) {
Recorder.record = true;
}

progressDialog.updateBarText("segment image...");
for(int x = 0; x < imp.getWidth(); x++){
Expand Down
4 changes: 2 additions & 2 deletions Thresholder/src/main/resources/plugins.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# Belongs to the MotiQ toolbox for analyzing cellular morphology, dynamics, and signaling (https://github.com/hansenjn/MotiQ). MotiQ_thresholder is a automated thresholding tool for image stacks. MotiQ thresholder calculates a threshold in a separate reference image and applies it to the input image. The reference image is optionally processed by MotiQ thresholder prior to threshold calculation, whereby the image histogram used for threshold calculation can be improved.

# Author: Jan N. Hansen <Jan.Hansen@uni-bonn.de>
# Version: 0.2.0
# Version: 0.2.1
# Date: 2017/09/15
# Requires: ImageJ

Plugins>MotiQ, "MotiQ Thresholder (v0.2.0)", motiQ_thr.Thresholder
Plugins>MotiQ, "MotiQ Thresholder (v0.2.1)", motiQ_thr.Thresholder

0 comments on commit fb542d3

Please sign in to comment.