private void doRGBProjection(ImageStack stack) { ImageStack[] channels = ChannelSplitter.splitRGB(stack, true); ImagePlus red = new ImagePlus("Red", channels[0]); ImagePlus green = new ImagePlus("Green", channels[1]); ImagePlus blue = new ImagePlus("Blue", channels[2]); imp.unlock(); ImagePlus saveImp = imp; imp = red; color = "(red)"; doProjection(); ImagePlus red2 = projImage; imp = green; color = "(green)"; doProjection(); ImagePlus green2 = projImage; imp = blue; color = "(blue)"; doProjection(); ImagePlus blue2 = projImage; int w = red2.getWidth(), h = red2.getHeight(), d = red2.getStackSize(); if (method == SD_METHOD) { ImageProcessor r = red2.getProcessor(); ImageProcessor g = green2.getProcessor(); ImageProcessor b = blue2.getProcessor(); double max = 0; double rmax = r.getStatistics().max; if (rmax > max) max = rmax; double gmax = g.getStatistics().max; if (gmax > max) max = gmax; double bmax = b.getStatistics().max; if (bmax > max) max = bmax; double scale = 255 / max; r.multiply(scale); g.multiply(scale); b.multiply(scale); red2.setProcessor(r.convertToByte(false)); green2.setProcessor(g.convertToByte(false)); blue2.setProcessor(b.convertToByte(false)); } RGBStackMerge merge = new RGBStackMerge(); ImageStack stack2 = merge.mergeStacks(w, h, d, red2.getStack(), green2.getStack(), blue2.getStack(), true); imp = saveImp; projImage = new ImagePlus(makeTitle(), stack2); }
public int setup(String arg, ImagePlus imp) { // IJ.register(Average_Oversampled.class); if (IJ.versionLessThan("1.32c")) return DONE; if (this.pre) { // before finding means imp.unlock(); this.imp = imp; this.nslices = imp.getNSlices(); this.width = imp.getWidth(); this.height = imp.getHeight(); this.slicecols = new float[nslices][width]; this.pre = false; return (DOES_ALL + DOES_STACKS + FINAL_PROCESSING); } else { // find SD after finding means of columns float sum; // sum of pixel values column float avg; // average pixel value of a column double devsum; // sum of deviations double devavg; // standard deviation double[] columns = new double[width]; // x-axis of plot double[] sdevs = new double[width]; // y-axis of plot for (int i = 0; i < width; i += 1) { sum = 0; // reset with each column avg = 0; // reset with each column devsum = 0; // reset with each column devavg = 0; // reset with each column columns[i] = i; // building x-axis for (int s = 0; s < nslices; s += 1) { // sum of column means sum = sum + slicecols[s][i]; } avg = sum / nslices; // mean of one column across all slices for (int s = 0; s < nslices; s += 1) { // standard deviation devsum = devsum + Math.pow((slicecols[s][i] - avg), 2); // square diff } devavg = Math.sqrt(devsum / nslices); sdevs[i] = devavg; // building y-axis } Plot plot = new Plot("Average SD by Column", "Columns", "Standard Deviation", columns, sdevs); plot.show(); // calculate CTN double ctn; double sdevssum = 0; for (double sd : sdevs) { sdevssum = sdevssum + sd; } ctn = sdevssum / width; // display CTN on results table ResultsTable rt = ResultsTable.getResultsTable(); // rt.incrementCounter(); rt.addValue("Column Temporal Noise", ctn); rt.show("Results"); this.pre = false; return DONE; } }
public void run(String arg) { imp = IJ.getImage(); int stackSize = imp.getStackSize(); if (imp == null) { IJ.noImage(); return; } // Make sure input image is a stack. if (stackSize == 1) { IJ.error("Z Project", "Stack required"); return; } // Check for inverting LUT. if (imp.getProcessor().isInvertedLut()) { if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return; } // Set default bounds. int channels = imp.getNChannels(); int frames = imp.getNFrames(); int slices = imp.getNSlices(); isHyperstack = imp.isHyperStack() || (ij.macro.Interpreter.isBatchMode() && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize))); boolean simpleComposite = channels == stackSize; if (simpleComposite) isHyperstack = false; startSlice = 1; if (isHyperstack) { int nSlices = imp.getNSlices(); if (nSlices > 1) stopSlice = nSlices; else stopSlice = imp.getNFrames(); } else stopSlice = stackSize; // Build control dialog GenericDialog gd = buildControlDialog(startSlice, stopSlice); gd.showDialog(); if (gd.wasCanceled()) return; if (!imp.lock()) return; // exit if in use long tstart = System.currentTimeMillis(); setStartSlice((int) gd.getNextNumber()); setStopSlice((int) gd.getNextNumber()); method = gd.getNextChoiceIndex(); Prefs.set(METHOD_KEY, method); if (isHyperstack) { allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false; doHyperStackProjection(allTimeFrames); } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true); else doProjection(true); if (arg.equals("") && projImage != null) { long tstop = System.currentTimeMillis(); projImage.setCalibration(imp.getCalibration()); if (simpleComposite) IJ.run(projImage, "Grays", ""); projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds"); } imp.unlock(); IJ.register(ZProjector.class); return; }