Skip to content

Commit cf9d0e0

Browse files
jdhardinctrueden
authored andcommitted
Replace red with magenta throughout the stack
This is very useful when one is converting a red/green stack to a magenta/green stack. Signed-off-by: Curtis Rueden <ctrueden@wisc.edu>
1 parent 62adb1e commit cf9d0e0

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>sc.fiji</groupId>
1313
<artifactId>Fiji_Plugins</artifactId>
14-
<version>3.1.4-SNAPSHOT</version>
14+
<version>3.2.0-SNAPSHOT</version>
1515

1616
<name>Fiji Plugins</name>
1717
<description>Fiji Plugins plugin for Fiji.</description>

src/main/java/fiji/color/Convert_Red_To_Magenta.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,26 @@
2121
*/
2222
package fiji.color;
2323

24+
import ij.IJ;
2425
import ij.ImagePlus;
26+
import ij.ImageStack;
27+
import ij.gui.GenericDialog;
2528
import ij.plugin.filter.PlugInFilter;
2629
import ij.process.ColorProcessor;
2730
import ij.process.ImageProcessor;
2831

2932
/**
30-
* Convert all reds to magentas (to help red-green blind viewers)
33+
* Convert all reds to magentas (to help red-green blind viewers).
34+
* <p>
35+
* Updated May 30, 2025 to apply to all slices in a stack
36+
* by Jeff Hardin, Dept. of Integrative Biology
37+
* Univ. of Wisconsin-Madison
38+
* </p>
3139
*/
3240
public class Convert_Red_To_Magenta implements PlugInFilter {
3341
protected ImagePlus image;
42+
public int numSlices, currentSlice;
43+
public ImageStack stack;
3444

3545
/**
3646
* This method gets called by ImageJ / Fiji to determine
@@ -40,6 +50,11 @@ public class Convert_Red_To_Magenta implements PlugInFilter {
4050
* @param image is the currently opened image
4151
*/
4252
public int setup(String arg, ImagePlus image) {
53+
if (image!= null) {
54+
stack = image.getStack();
55+
numSlices = stack.getSize(); // Get the number of slices
56+
currentSlice = image.getCurrentSlice(); // Get current slice
57+
}
4358
this.image = image;
4459
return DOES_RGB;
4560
}
@@ -51,8 +66,34 @@ public int setup(String arg, ImagePlus image) {
5166
* the ImagePlus set above instead).
5267
*/
5368
public void run(ImageProcessor ip) {
54-
process((ColorProcessor)ip);
55-
image.updateAndDraw();
69+
if (stack.isVirtual()) {
70+
IJ.showMessage("Virtual Stack", "This plugin does not support virtual stacks.");
71+
return;
72+
}
73+
74+
if (numSlices == 1) {
75+
process((ColorProcessor)ip);
76+
image.updateAndDraw();
77+
}
78+
else {
79+
//Ask user if OK to apply to all slices in a stack
80+
GenericDialog gd = new GenericDialog("Apply to entire stack?");
81+
gd.addMessage("Replace red with magenta in all slices?\n \n" +
82+
"NOTE: There is no undo for this operation.");
83+
gd.showDialog();
84+
if (gd.wasCanceled()) {
85+
return;
86+
}
87+
for (int i = 0; i < numSlices; i++) {
88+
//image.setSlice(i+1);
89+
IJ.showStatus("Processing slice " + (i+1) + " of " + numSlices);
90+
IJ.showProgress(i/numSlices);
91+
ImageProcessor ip2 = stack.getProcessor(i+1);
92+
process((ColorProcessor)ip2);
93+
}
94+
image.setSlice(currentSlice);
95+
image.updateAndDraw();
96+
}
5697
}
5798

5899
public static void process(ColorProcessor ip) {

0 commit comments

Comments
 (0)