2121 */
2222package fiji .color ;
2323
24+ import ij .IJ ;
2425import ij .ImagePlus ;
26+ import ij .ImageStack ;
27+ import ij .gui .GenericDialog ;
2528import ij .plugin .filter .PlugInFilter ;
2629import ij .process .ColorProcessor ;
2730import 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*/
3240public 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