/* * Multichannel_ZT-axis_Profile.bsh * IJ BAR: https://github.com/tferr/Scripts#scripts * * BeanShell script that extends Image>Stack>Plot Z-axis Profile to multichannel (composite) images. * It features a "live" option, guesses displayed lookup tables and ignores disabled channels (i.e., * those deselected in the "Channels" widget (Image>Color>Channels Tool). * * N.B.: * - Intensities (mean, min or max) are retrieved from active ROI or entire canvas if no ROI exists * - With hyperstacks, intensities can be averaged across Z-slices at each time point * - Limits of Y-axis are set to include data from all visible channels */ import bar.Utils; import ij.CompositeImage; import ij.IJ; import ij.ImagePlus; import ij.ImageStack; import ij.WindowManager; import ij.gui.GenericDialog; import ij.gui.Plot; import ij.gui.Roi; import ij.measure.Calibration; import ij.measure.ResultsTable; import ij.process.ImageProcessor; import ij.process.ImageStatistics; import ij.util.Tools; import java.awt.Color; import java.awt.image.IndexColorModel; import java.util.Arrays; /* Options for Plot's y-axis values */ String[] yOptions = new String[] {"Mean", "Max", "Min"}; /* Default choice for y-axis value */ String yOption = yOptions[0]; /* Default choice for calibrated x-axis */ boolean calibratedX = true; /* Default choice for Z-slice averaging */ boolean averageZ = true; /* Allow Ctrl triggering of customRoutine when in live mode? */ boolean allowRoutine = true; /* This method is called when the user presses Ctrl in live mode. It takes * the profile of the active channel and does something with it. In this * case it obtains a histogram of the profiled data. It does so by placing * the list of profiled values in the Results table before calling the * Distribution_Plotter IJ1 macro (Part of BAR). * * Note that this is a rather convoluted way of performing such task. However, * it does showcase cooperation among BAR routines written in different * languages. */ void customRoutine(double[] values) { rt = ResultsTable.getResultsTable(); if (ResultsTable.getResultsWindow() == null || rt.getCounter() == 0) rt = new ResultsTable(); colHeading = "ActiveProfile"; for (i=0; imax) max = value; } } return new double[] {min, max}; } /* Returns the ImageStatistics measure specified by the user */ double getIntensity(ImageStatistics stats) { if (super.yOption.equals(super.yOptions[0])) return stats.mean; else if (super.yOption.equals(super.yOptions[1])) return stats.max; else return stats.min; } /* * Returns the color associated with the specified LUT. See * ij.CompositeImage.getChannelColor() */ Color getLutColor(IndexColorModel cm) { int index = cm.getMapSize() - 1; int r = cm.getRed(index); int g = cm.getGreen(index); int b = cm.getBlue(index); if (r<100 || g<100 || b<100) return new Color(r, g, b); else return Color.BLACK; } /* Returns an array of colors with the specified size */ Color[] getUniqueColors(int n) { Color[] defaults = {Color.BLACK, Color.DARK_GRAY, Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.YELLOW}; Color[] newcolors = new Color[n]; for (int i=0; i