import ij.*; import ij.process.*; import ij.gui.*; import ij.measure.*; import java.awt.*; import java.awt.event.*; import java.math.*; import javax.swing.*; import ij.plugin.*; import ij.plugin.filter.*; import ij.plugin.PlugIn; import org.math.plot.*; import org.math.array.*; import org.math.io.*; public class S1_Histogram implements PlugInFilter { ImagePlus imp; protected ImageStack stackin; double time; static int x = 2; static int y = 15; static int size = 12; int maxWidth; Font font; static double start = 0; static double interval = 1; static double readNoiseX3 = 10; // in ADU static double binWidth = 4; // in ADUs static String subtractOffset = "yes"; static int decimalPlaces = 0; boolean canceled; int frame, first, last; int numFramesPerSet = 3; Rectangle roi; double totalDarkValue = 0; double avgDarkValue = 0; int histogramSize = 500; static double seedThreshold = 20; static double cleanThreshold = .7; int column = 1; int fCRIC = 1; //int readNoiseX3 = 6; public int setup(String arg, ImagePlus imp) { if (IJ.versionLessThan("1.32c")) return DONE; this.imp = imp; stackin = imp.getStack(); IJ.register(Photon_Transfer.class); if (imp!=null) { first = 1; last = imp.getStackSize(); } return DOES_ALL; } public void run(ImageProcessor ip) { JFrame windowPlotKHistogram; Plot2DPanel PlotKHistogram; boolean seed; double[][] histS1Clean = new double[histogramSize][2]; for (int i=0; i= seedThreshold) { seed = true; value_S9 = 0; for (int deltaX = -1; deltaX <= 1; deltaX++) { for (int deltaY = -1; deltaY <= 1; deltaY++) { // only add pixels above the read noise! value = ipSlice.getPixelValue(x+deltaX,y+deltaY); if (value > readNoiseX3) value_S9 += ipSlice.getPixelValue(x+deltaX,y+deltaY); if ( ipSlice.getPixelValue(x+deltaX,y+deltaY) > value_S1) // exit if adjacent pixel is larger { deltaX = 1; deltaY = 1; seed = false; } } } // test for clean S1 if (seed == true) { if (value_S1/value_S9 >= cleanThreshold) { if (value_S1 < histogramSize - binWidth) { for (int ii=0; ii< binWidth; ii++) { histS1Clean[(int)( (int)(value_S1/binWidth)*binWidth) +ii][1] += 1; } } // if you want to put large pixels at end of histogram else histS1Clean[(int)histogramSize-1][1] += 1; } } } // if seed } // roi x } // roi y //} } // for stack //*************************************************** // create a new window with KHistogram Plot2DPanel plotKHistogram = new Plot2DPanel(); plotKHistogram.addLegend("SOUTH"); plotKHistogram.addLinePlot("S1, seed >" + seedThreshold + ", s1/s9 > " + cleanThreshold , histS1Clean); plotKHistogram.setAxisLabel(0,"ADU"); plotKHistogram.setAxisLabel(1,"Occurrences"); plotKHistogram.setAutoBounds(0); plotKHistogram.setAutoBounds(1); //plotKHistogram.addLinePlot("S1 Clean", valueS1Clean); //plotKHistogram.addLinePlot("S2 Clean, s2/aroundS2 > " + cleanThreshold, histS2); //plotKHistogram.addLinePlot("S4 Clean, s4/aroundS4 > " + cleanThreshold, histS4); //plotKHistogram.addLinePlot("S9 rest", histS9); //plotKHistogram.addLinePlot("SumOfCleans", histOfClean); windowPlotKHistogram = new JFrame(); windowPlotKHistogram.setContentPane(plotKHistogram); windowPlotKHistogram.setTitle("ADC vs Occurrences"); windowPlotKHistogram.pack(); windowPlotKHistogram.setVisible(true); windowPlotKHistogram.setFocusable(true); windowPlotKHistogram.requestFocusInWindow(); windowPlotKHistogram.setSize(500,500); } // will evenutally ask for stack information void showDialog(ImageProcessor ip) { //Rectangle roi = ip.getRoi(); if (roi.width80) size = 80; } GenericDialog gd = new GenericDialog("S1 Histogram Plot"); gd.addNumericField("Seed Threshold >=", seedThreshold, 0); gd.addNumericField("Clean Threshold (S1/S9 <)", cleanThreshold, 2); gd.addNumericField("Selection Bounds xbase", roi.x, 0); gd.addNumericField("Selection Bounds ybase", roi.y, 0); gd.addNumericField("Selection Bounds width", roi.width, 0); gd.addNumericField("Selection Bounds height", roi.height, 0); gd.addNumericField("First Frame:", first, 0); gd.addNumericField("Last Frame:", last, 0); gd.addNumericField("Read Noise (ADU)", readNoiseX3, 0); gd.addNumericField("Bin Width (ADUs)", binWidth, 0); gd.showDialog(); if (gd.wasCanceled()) {canceled = true; return;} seedThreshold = gd.getNextNumber(); cleanThreshold = gd.getNextNumber(); x = (int)gd.getNextNumber(); y = (int)gd.getNextNumber(); size = (int)gd.getNextNumber(); decimalPlaces = (int)gd.getNextNumber(); first = (int)gd.getNextNumber(); last = (int)gd.getNextNumber(); readNoiseX3 = gd.getNextNumber(); binWidth = gd.getNextNumber(); font = new Font("SansSerif", Font.PLAIN, size); ip.setFont(font); time = start; if (y