public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { if (doOptions) { this.imp = imp; this.pfr = pfr; GenericDialog gd = new GenericDialog("Binary Options"); gd.addNumericField("Iterations (1-" + MAX_ITERATIONS + "):", iterations, 0, 3, ""); gd.addNumericField("Count (1-8):", count, 0, 3, ""); gd.addCheckbox("Black background", Prefs.blackBackground); gd.addCheckbox("Pad edges when eroding", Prefs.padEdges); gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]); if (imp != null) { gd.addChoice("Do:", operations, operation); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); previewing = true; } gd.addHelp(IJ.URL + "/docs/menus/process.html#options"); gd.showDialog(); previewing = false; if (gd.wasCanceled()) return DONE; if (imp == null) { // options dialog only, no do/preview dialogItemChanged(gd, null); // read dialog result return DONE; } return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags); } else { // no dialog, 'arg' is operation type if (!((ByteProcessor) imp.getProcessor()).isBinary()) { IJ.error("8-bit binary (black and white only) image required."); return DONE; } return IJ.setupDialog(imp, flags); } }
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { this.pfr = pfr; String macroOptions = Macro.getOptions(); if (macroOptions != null) { if (macroOptions.indexOf(" interpolate") != -1) macroOptions.replaceAll(" interpolate", " interpolation=Bilinear"); else if (macroOptions.indexOf(" interpolation=") == -1) macroOptions = macroOptions + " interpolation=None"; Macro.setOptions(macroOptions); } gd = new GenericDialog("Rotate", IJ.getInstance()); gd.addNumericField("Angle (degrees):", angle, (int) angle == angle ? 1 : 2); gd.addNumericField("Grid Lines:", gridLines, 0); gd.addChoice("Interpolation:", methods, methods[interpolationMethod]); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with Background Color", fillWithBackground); if (canEnlarge) gd.addCheckbox("Enlarge Image to Fit Result", enlarge); else enlarge = false; gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.showDialog(); drawGridLines(0); if (gd.wasCanceled()) { return DONE; } if (!enlarge) flags |= KEEP_PREVIEW; // standard filter without enlarge else if (imp.getStackSize() == 1) flags |= NO_CHANGES; // undoable as a "compound filter" return IJ.setupDialog(imp, flags); }
/** * Creates a dialog box, allowing the user to enter the requested width, height, x & y * coordinates, slice number for a Region Of Interest, option for oval, and option for whether x & * y coordinates to be centered. */ void showDialog() { Calibration cal = imp.getCalibration(); int digits = 0; if (scaledUnits && cal.scaled()) digits = 2; Roi roi = imp.getRoi(); if (roi == null) drawRoi(); GenericDialog gd = new GenericDialog("Specify"); gd.addNumericField("Width:", width, digits); gd.addNumericField("Height:", height, digits); gd.addNumericField("X coordinate:", xRoi, digits); gd.addNumericField("Y coordinate:", yRoi, digits); if (stackSize > 1) gd.addNumericField("Slice:", iSlice, 0); gd.addCheckbox("Oval", oval); gd.addCheckbox("Constrain square/circle", square); gd.addCheckbox("Centered", centered); if (cal.scaled()) { boolean unitsMatch = cal.getXUnit().equals(cal.getYUnit()); String units = unitsMatch ? cal.getUnits() : cal.getXUnit() + " x " + cal.getYUnit(); gd.addCheckbox("Scaled units (" + units + ")", scaledUnits); } fields = gd.getNumericFields(); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) { if (roi == null) imp.deleteRoi(); else // *ALWAYS* restore initial ROI when cancelled imp.setRoi(roi); } }
/** * Builds dialog to query users for projection parameters. * * @param start starting slice to display * @param stop last slice */ protected GenericDialog buildControlDialog(int start, int stop) { GenericDialog gd = new GenericDialog("ZProjection", IJ.getInstance()); gd.addNumericField("Start slice:", startSlice, 0 /*digits*/); gd.addNumericField("Stop slice:", stopSlice, 0 /*digits*/); gd.addChoice("Projection type", METHODS, METHODS[method]); if (isHyperstack && imp.getNFrames() > 1 && imp.getNSlices() > 1) gd.addCheckbox("All time frames", allTimeFrames); return gd; }
public boolean beadCalibration3d() { imp = IJ.getImage(); if (imp == null) { IJ.noImage(); return false; } else if (imp.getStackSize() == 1) { IJ.error("Stack required"); return false; } else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16) { // In order to support 32bit images, pict[] must be changed to float[], and getPixel(x, y); // requires a Float.intBitsToFloat() conversion IJ.error("8 or 16 bit greyscale image required"); return false; } width = imp.getWidth(); height = imp.getHeight(); nslices = imp.getStackSize(); imtitle = imp.getTitle(); models[0] = "*None*"; models[1] = "line"; models[2] = "2nd degree polynomial"; models[3] = "3rd degree polynomial"; models[4] = "4th degree polynomial"; GenericDialog gd = new GenericDialog("3D PALM calibration"); gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.3Dcal_fwhm", 20), 0); gd.addNumericField( "Particle local threshold (% maximum intensity)", prefs.get("QuickPALM.pthrsh", 20), 0); gd.addNumericField("Z-spacing (nm)", prefs.get("QuickPALM.z-step", 10), 2); gd.addNumericField("Calibration Z-smoothing (radius)", prefs.get("QuickPALM.window", 1), 0); gd.addChoice("Model", models, prefs.get("QuickPALM.model", models[3])); gd.addCheckbox( "Show divergence of bead positions against model", prefs.get("QuickPALM.3Dcal_showDivergence", false)); gd.addCheckbox("Show extra particle info", prefs.get("QuickPALM.3Dcal_showExtraInfo", false)); gd.addMessage("\n\nDon't forget to save the table in the end..."); gd.showDialog(); if (gd.wasCanceled()) return false; fwhm = gd.getNextNumber(); prefs.set("QuickPALM.QuickPALM.3Dcal_fwhm", fwhm); pthrsh = gd.getNextNumber() / 100; prefs.set("QuickPALM.pthrsh", pthrsh * 100); cal_z = gd.getNextNumber(); prefs.set("QuickPALM.z-step", cal_z); window = (int) gd.getNextNumber(); prefs.set("QuickPALM.window", window); model = gd.getNextChoice(); prefs.set("QuickPALM.model", model); part_divergence = gd.getNextBoolean(); prefs.set("QuickPALM.3Dcal_showDivergence", part_divergence); part_extrainfo = gd.getNextBoolean(); prefs.set("QuickPALM.3Dcal_showExtraInfo", part_extrainfo); return true; }
void showDialog() { int width = imp.getWidth(); int height = imp.getHeight(); Calibration cal = imp.getCalibration(); int places; if (cal.scaled()) { pixelWidth = cal.pixelWidth; pixelHeight = cal.pixelHeight; units = cal.getUnits(); places = 2; } else { pixelWidth = 1.0; pixelHeight = 1.0; units = "pixels"; places = 0; } if (areaPerPoint == 0.0) areaPerPoint = (width * cal.pixelWidth * height * cal.pixelHeight) / 81.0; // default to 9x9 grid ImageWindow win = imp.getWindow(); GenericDialog gd = new GenericDialog("Grid..."); gd.addChoice("Grid Type:", types, type); gd.addNumericField("Area per Point:", areaPerPoint, places, 6, units + "^2"); gd.addChoice("Color:", colors, color); gd.addCheckbox("Random Offset", randomOffset); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) showGrid(null); }
void interpolate() { Roi roi = imp.getRoi(); if (roi == null) { noRoi("Interpolate"); return; } if (roi.getType() == Roi.POINT) return; if (IJ.isMacro() && Macro.getOptions() == null) Macro.setOptions("interval=1"); GenericDialog gd = new GenericDialog("Interpolate"); gd.addNumericField("Interval:", 1.0, 1, 4, "pixel"); gd.addCheckbox("Smooth", IJ.isMacro() ? false : smooth); gd.showDialog(); if (gd.wasCanceled()) return; double interval = gd.getNextNumber(); smooth = gd.getNextBoolean(); Undo.setup(Undo.ROI, imp); FloatPolygon poly = roi.getInterpolatedPolygon(interval, smooth); int t = roi.getType(); int type = roi.isLine() ? Roi.FREELINE : Roi.FREEROI; if (t == Roi.POLYGON && interval > 1.0) type = Roi.POLYGON; if ((t == Roi.RECTANGLE || t == Roi.OVAL || t == Roi.FREEROI) && interval >= 5.0) type = Roi.POLYGON; if ((t == Roi.LINE || t == Roi.FREELINE) && interval >= 5.0) type = Roi.POLYLINE; if (t == Roi.POLYLINE && interval >= 1.0) type = Roi.POLYLINE; ImageCanvas ic = imp.getCanvas(); if (poly.npoints <= 150 && ic != null && ic.getMagnification() >= 12.0) type = roi.isLine() ? Roi.POLYLINE : Roi.POLYGON; Roi p = new PolygonRoi(poly, type); if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth()); p.setStrokeColor(roi.getStrokeColor()); p.setName(roi.getName()); transferProperties(roi, p); imp.setRoi(p); }
// Input/Output options void io() { GenericDialog gd = new GenericDialog("I/O Options"); gd.addNumericField("JPEG quality (0-100):", FileSaver.getJpegQuality(), 0, 3, ""); gd.addNumericField("GIF and PNG transparent index:", Prefs.getTransparentIndex(), 0, 3, ""); gd.addStringField( "File extension for tables (.txt, .xls or .csv):", Prefs.get("options.ext", ".csv"), 4); gd.addCheckbox("Use JFileChooser to open/save", Prefs.useJFileChooser); if (!IJ.isMacOSX()) gd.addCheckbox("Use_file chooser to import sequences", Prefs.useFileChooser); gd.addCheckbox("Save TIFF and raw in Intel byte order", Prefs.intelByteOrder); gd.addCheckbox("Skip dialog when opening .raw files", Prefs.skipRawDialog); gd.setInsets(15, 20, 0); gd.addMessage("Results Table Options"); gd.setInsets(3, 40, 0); gd.addCheckbox("Copy_column headers", Prefs.copyColumnHeaders); gd.setInsets(0, 40, 0); gd.addCheckbox("Copy_row numbers", !Prefs.noRowNumbers); gd.setInsets(0, 40, 0); gd.addCheckbox("Save_column headers", !Prefs.dontSaveHeaders); gd.setInsets(0, 40, 0); gd.addCheckbox("Save_row numbers", !Prefs.dontSaveRowNumbers); gd.showDialog(); if (gd.wasCanceled()) return; int quality = (int) gd.getNextNumber(); if (quality < 0) quality = 0; if (quality > 100) quality = 100; FileSaver.setJpegQuality(quality); int transparentIndex = (int) gd.getNextNumber(); Prefs.setTransparentIndex(transparentIndex); String extension = gd.getNextString(); if (!extension.startsWith(".")) extension = "." + extension; Prefs.set("options.ext", extension); Prefs.useJFileChooser = gd.getNextBoolean(); if (!IJ.isMacOSX()) Prefs.useFileChooser = gd.getNextBoolean(); Prefs.intelByteOrder = gd.getNextBoolean(); Prefs.skipRawDialog = gd.getNextBoolean(); Prefs.copyColumnHeaders = gd.getNextBoolean(); Prefs.noRowNumbers = !gd.getNextBoolean(); Prefs.dontSaveHeaders = !gd.getNextBoolean(); Prefs.dontSaveRowNumbers = !gd.getNextBoolean(); return; }
private boolean showDialog() { String[] types = {"RAW", "JPEG", "ZLIB"}; GenericDialog gd = new GenericDialog("Generate Bricks"); gd.addChoice("FileType", types, filetype); gd.addNumericField("JPEG quality", jpeg_quality, 0); gd.addNumericField("Max file size (MB)", bdsizelimit, 0); int[] wlist = WindowManager.getIDList(); if (wlist == null) return false; String[] titles = new String[wlist.length]; for (int i = 0; i < wlist.length; i++) titles[i] = ""; int tnum = 0; for (int i = 0; i < wlist.length; i++) { ImagePlus imp = WindowManager.getImage(wlist[i]); if (imp != null) { titles[tnum] = imp.getTitle(); tnum++; } } gd.addChoice("Source image: ", titles, titles[0]); gd.showDialog(); if (gd.wasCanceled()) return false; filetype = types[gd.getNextChoiceIndex()]; jpeg_quality = (int) gd.getNextNumber(); if (jpeg_quality > 100) jpeg_quality = 100; if (jpeg_quality < 0) jpeg_quality = 0; bdsizelimit = (int) gd.getNextNumber(); int id = gd.getNextChoiceIndex(); lvImgTitle = new ArrayList<String>(); lvImgTitle.add(titles[id]); Prefs.set("filetype.string", filetype); Prefs.set("jpeg_quality.int", jpeg_quality); Prefs.set("bdsizelimit.int", bdsizelimit); return true; }
boolean showoptions(double[] params, int[] fixes) { // GenericDialog gd=new NonBlockingGenericDialog("Options"); GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Check Chi Squared", checkc2); for (int i = 0; i < 10; i++) { gd.addNumericField("P" + (i + 1), params[i], 5, 10, null); gd.addCheckbox("Fix?", (fixes[i] == 1)); } gd.addCheckbox("Get_Errors", false); gd.addCheckbox("Set_Constraints", false); gd.addNumericField("Iterations", iterations, 0, 10, null); gd.addNumericField("chi squared", c2, 5, 10, null); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) { return false; } checkc2 = gd.getNextBoolean(); for (int i = 0; i < 10; i++) { params[i] = gd.getNextNumber(); if (gd.getNextBoolean()) { fixes[i] = 1; } else { fixes[i] = 0; } } boolean geterrors = gd.getNextBoolean(); boolean setconstraints = gd.getNextBoolean(); for (int i = 0; i < 10; i++) { if (function.indexOf("P" + (i + 1)) < 0) { fixes[i] = 1; } } if (geterrors) { if (!get_errors(params, fixes)) { return false; } } if (setconstraints) constraints = get_constraints(params); return true; }
public double[][] get_constraints(double[] params) { // here we populate the constraints GenericDialog gd = new GenericDialog("Constraints"); for (int i = 0; i < 10; i++) { if (constraints == null) { gd.addNumericField("P" + (i + 1) + "_upper", params[i], 5, 10, null); gd.addNumericField("P" + (i + 1) + "_lower", params[i], 5, 10, null); } else { gd.addNumericField("P" + (i + 1) + "_upper", constraints[1][i], 5, 10, null); gd.addNumericField("P" + (i + 1) + "_lower", constraints[0][i], 5, 10, null); } } gd.showDialog(); if (gd.wasCanceled()) { return null; } double[][] constraints = new double[2][10]; for (int i = 0; i < 10; i++) { constraints[1][i] = gd.getNextNumber(); constraints[0][i] = gd.getNextNumber(); } return constraints; }
public boolean showDialog(ImageStack stack) { hyperstack = imp.isHyperStack(); boolean showCheckbox = false; if (hyperstack && imp.getNSlices() > 1 && imp.getNFrames() > 1) showCheckbox = true; else if (hyperstack && imp.getNSlices() > 1) reduceSlices = true; int n = stack.getSize(); GenericDialog gd = new GenericDialog("Reduce Size"); gd.addNumericField("Reduction Factor:", factor, 0); if (showCheckbox) gd.addCheckbox("Reduce in Z-Dimension", false); gd.showDialog(); if (gd.wasCanceled()) return false; factor = (int) gd.getNextNumber(); if (showCheckbox) reduceSlices = gd.getNextBoolean(); return true; }
public void run(String arg) { int[] wList = WindowManager.getIDList(); if (wList==null) { IJ.error("No images are open."); return; } double kernel=3; double kernelsum = 0; double kernelvarsum =0; double kernalvar = 0; double sigmawidth = 2; int kernelindex, minpixnumber; String[] kernelsize = { "3�,"5�, "7�, "9�}; GenericDialog gd = new GenericDialog("Sigma Filter"); gd.addChoice("Kernel size", kernelsize, kernelsize[0]); gd.addNumericField("Sigma width",sigmawidth , 2); gd.addNumericField("Minimum number of pixels", 1, 0); gd.addCheckbox("Keep source:",true); gd.addCheckbox("Do all stack:",true); gd.addCheckbox("Modified Lee's FIlter:",true); gd.showDialog(); if (gd.wasCanceled()) return ; kernelindex = gd.getNextChoiceIndex(); sigmawidth = gd.getNextNumber(); minpixnumber = ((int)gd.getNextNumber()); boolean keep = gd.getNextBoolean(); boolean doallstack = gd.getNextBoolean(); boolean modified = gd.getNextBoolean(); if (kernelindex==0) kernel = 3; if (kernelindex==1) kernel = 5; if (kernelindex==2) kernel = 7; if (kernelindex==3) kernel = 9; long start = System.currentTimeMillis(); if (minpixnumber> (kernel*kernel)){ IJ.showMessage("Sigma filter", "There must be more pixels in the kernel than+\n" + "the minimum number to be included"); return; } double v, midintensity; int x, y, ix, iy; double sum = 0; double backupsum =0; int count = 0; int n = 0; if (keep) {IJ.run("Select All"); IJ.run("Duplicate...", "title='Sigma filtered' duplicate");} int radius = (int)(kernel-1)/2; ImagePlus imp = WindowManager.getCurrentImage(); ImageStack stack1 = imp.getStack(); int width = imp.getWidth(); int height = imp.getHeight(); int nslices = stack1.getSize(); int cslice = imp.getCurrentSlice(); double status = width*height*nslices; ImageProcessor ip = imp.getProcessor(); int sstart = 1; if (!doallstack) {sstart = cslice; nslices=sstart;status = status/nslices;}; for (int i=sstart; i<=nslices; i++) { imp.setSlice(i); for (x=radius;x<width+radius;x++) { for (y=radius;y<height+radius;y++) { midintensity = ip.getPixelValue(x,y); count = 0; sum = 0; kernelsum =0; kernalvar =0; kernelvarsum =0; backupsum = 0; //calculate mean of kernel value for (ix=0;ix<kernel;ix++) { for (iy=0;iy<kernel;iy++) { v = ip.getPixelValue(x+ix-radius,y+iy-radius); kernelsum = kernelsum+v; } } double sigmacalcmean = (kernelsum/(kernel*kernel)); //calculate variance of kernel for (ix=0;ix<kernel;ix++) { for (iy=0;iy<kernel;iy++) { v = ip.getPixelValue(x+ix-radius,y+iy-radius); kernalvar = (v-sigmacalcmean)*(v-sigmacalcmean); kernelvarsum = kernelvarsum + kernalvar; } } //double variance = kernelvarsum/kernel; double sigmacalcvar = kernelvarsum/((kernel*kernel)-1); //calcuate sigma range = sqrt(variance/(mean^2)) � sigmawidth double sigmarange = sigmawidth*(Math.sqrt((sigmacalcvar) /(sigmacalcmean*sigmacalcmean))); //calulate sigma top value and bottom value double sigmatop = midintensity*(1+sigmarange); double sigmabottom = midintensity*(1-sigmarange); //calculate mean of values that differ are in sigma range. for (ix=0;ix<kernel;ix++) { for (iy=0;iy<kernel;iy++) { v = ip.getPixelValue(x+ix-radius,y+iy-radius); if ((v>=sigmabottom)&&(v<=sigmatop)){ sum = sum+v; count = count+1; } backupsum = v+ backupsum; } } //if there are too few pixels in the kernal that are within sigma range, the //mean of the entire kernal is taken. My modification of Lee's filter is to exclude the central value //from the calculation of the mean as I assume it to be spuriously high or low if (!(count>(minpixnumber))) {sum = (backupsum-midintensity); count = (int)((kernel*kernel)-1); if (!modified) {sum = (backupsum); count = (int)(kernel*kernel);} } double val = (sum/count); ip.putPixelValue(x,y, val); n = n+1; double percentage = (((double)n/status)*100); IJ.showStatus(IJ.d2s(percentage,0) +"% done"); } // IJ.showProgress(i, status); }} imp.updateAndDraw(); IJ.showStatus(IJ.d2s((System.currentTimeMillis()-start)/1000.0, 2)+" seconds"); }
private void makeBand(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null) { noRoi("Make Band"); return; } if (!roi.isArea()) { IJ.error("Make Band", "Area selection required"); return; } Calibration cal = imp.getCalibration(); double pixels = bandSize; double size = pixels * cal.pixelWidth; int decimalPlaces = 0; if ((int) size != size) decimalPlaces = 2; GenericDialog gd = new GenericDialog("Make Band"); gd.addNumericField("Band Size:", size, decimalPlaces, 4, cal.getUnits()); gd.showDialog(); if (gd.wasCanceled()) return; size = gd.getNextNumber(); if (Double.isNaN(size)) { IJ.error("Make Band", "invalid number"); return; } int n = (int) Math.round(size / cal.pixelWidth); if (n > 255) { IJ.error("Make Band", "Cannot make bands wider that 255 pixels"); return; } int width = imp.getWidth(); int height = imp.getHeight(); Rectangle r = roi.getBounds(); ImageProcessor ip = roi.getMask(); if (ip == null) { ip = new ByteProcessor(r.width, r.height); ip.invert(); } ImageProcessor mask = new ByteProcessor(width, height); mask.insert(ip, r.x, r.y); ImagePlus edm = new ImagePlus("mask", mask); boolean saveBlackBackground = Prefs.blackBackground; Prefs.blackBackground = false; IJ.run(edm, "Distance Map", ""); Prefs.blackBackground = saveBlackBackground; ip = edm.getProcessor(); ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE); int xx = -1, yy = -1; for (int x = r.x; x < r.x + r.width; x++) { for (int y = r.y; y < r.y + r.height; y++) { if (ip.getPixel(x, y) < n) { xx = x; yy = y; break; } } if (xx >= 0 || yy >= 0) break; } int count = IJ.doWand(edm, xx, yy, 0, null); if (count <= 0) { IJ.error("Make Band", "Unable to make band"); return; } ShapeRoi roi2 = new ShapeRoi(edm.getRoi()); if (!(roi instanceof ShapeRoi)) roi = new ShapeRoi(roi); ShapeRoi roi1 = (ShapeRoi) roi; roi2 = roi2.not(roi1); imp.setRoi(roi2); bandSize = n; }
void addImage() { ImagePlus imp = IJ.getImage(); int[] wList = WindowManager.getIDList(); if (wList == null || wList.length < 2) { IJ.error("Add Image...", "The command requires at least two open images."); return; } String[] titles = new String[wList.length]; for (int i = 0; i < wList.length; i++) { ImagePlus imp2 = WindowManager.getImage(wList[i]); titles[i] = imp2 != null ? imp2.getTitle() : ""; } int x = 0, y = 0; Roi roi = imp.getRoi(); if (roi != null && roi.isArea()) { Rectangle r = roi.getBounds(); x = r.x; y = r.y; } int index = 0; if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) index = 1; } else if (imp.getID() == wList[0]) index = 1; GenericDialog gd = new GenericDialog("Add Image..."); gd.addChoice("Image to add:", titles, titles[index]); gd.addNumericField("X location:", x, 0); gd.addNumericField("Y location:", y, 0); gd.addNumericField("Opacity (0-100%):", 100, 0); gd.addCheckbox("Create image selection", createImageRoi); gd.showDialog(); if (gd.wasCanceled()) return; index = gd.getNextChoiceIndex(); x = (int) gd.getNextNumber(); y = (int) gd.getNextNumber(); double opacity = gd.getNextNumber() / 100.0; createImageRoi = gd.getNextBoolean(); ImagePlus overlay = WindowManager.getImage(wList[index]); if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) { imp = i1; overlay = i2; } } if (overlay == imp) { IJ.error( "Add Image...", "Image to be added cannot be the same as\n\"" + imp.getTitle() + "\"."); return; } if (overlay.getWidth() > imp.getWidth() && overlay.getHeight() > imp.getHeight()) { IJ.error( "Add Image...", "Image to be added cannnot be larger than\n\"" + imp.getTitle() + "\"."); return; } if (createImageRoi && x == 0 && y == 0) { x = imp.getWidth() / 2 - overlay.getWidth() / 2; y = imp.getHeight() / 2 - overlay.getHeight() / 2; } roi = new ImageRoi(x, y, overlay.getProcessor()); roi.setName(overlay.getShortTitle()); if (opacity != 1.0) ((ImageRoi) roi).setOpacity(opacity); if (createImageRoi) imp.setRoi(roi); else { Overlay overlayList = imp.getOverlay(); if (overlayList == null) overlayList = new Overlay(); overlayList.add(roi); imp.setOverlay(overlayList); overlay2 = overlayList; Undo.setup(Undo.OVERLAY_ADDITION, imp); } }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); double sfreq = 20000.0; gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null); String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"}; gd.addChoice("PSF Type?", psfchoice, psfchoice[0]); String[] filetypechoice = { "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File" }; gd.addChoice("File Type?", filetypechoice, filetypechoice[0]); boolean ch2green = true; gd.addCheckbox("Ch2 is green?", ch2green); gd.showDialog(); if (gd.wasCanceled()) { return; } sfreq = gd.getNextNumber(); int psfflag = gd.getNextChoiceIndex(); int fileflag = gd.getNextChoiceIndex(); ch2green = gd.getNextBoolean(); int nfiles = 0; Object[] histograms = null; int xmax = 0; int ymax = 0; String[] names = null; if (fileflag < 2) { jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length / 2; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = organize_c3_files(filearray); for (int i = 0; i < nfiles; i++) { try { int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0); int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0); int length3 = (int) (((double) filearray[2 * i].length()) / 2.0); int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0); InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i])); InputStream instream2 = new BufferedInputStream(new FileInputStream(filearray[2 * i + 1])); if (fileflag == 0) { int[] pmdata = new int[length1]; int[] pmdata2 = new int[length2]; if (!ioclass.skipstreambytes(instream, 128)) { showioerror(); instream.close(); return; } if (!ioclass.skipstreambytes(instream2, 128)) { showioerror(); instream2.close(); return; } if (!ioclass.readintelintfile(instream, length1, pmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelintfile(instream2, length2, pmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000); } else { histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000); } } else { float[] tmdata = new float[length3]; float[] tmdata2 = new float[length4]; if (!ioclass.readintelshortfile(instream, length3, tmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata); } else { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2); } } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } instream.close(); instream2.close(); } catch (IOException e) { showioerror(); return; } } } else { if (fileflag == 2) { ImageWindow iw = WindowManager.getCurrentWindow(); float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); sfreq = 1.0 / ((double) tempxvals[0][1]); nfiles = trajectories.length / 2; if (nfiles > 25) { nfiles = 25; } names = new String[nfiles + 1]; names[nfiles] = "avg"; histograms = new Object[nfiles]; for (int i = 0; i < nfiles; i++) { names[i] = "trajectory " + (i + 1); if (ch2green) { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]); } else { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]); } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } else { // here we read tab delimited lines from files jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = new String[nfiles + 1]; names[nfiles] = "avg"; for (int i = 0; i < nfiles; i++) { try { names[i] = filearray[i].getName(); BufferedReader d = new BufferedReader(new FileReader(filearray[i])); String[] lines = new String[256]; int counter = 0; do { lines[counter] = d.readLine(); counter++; } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256); int numcolumns = 0; for (int j = 0; j < counter - 1; j++) { int temp = getncolumns(lines[j]); if (temp > numcolumns) { numcolumns = temp; } } float[][] temphist2 = null; if (ch2green) { temphist2 = new float[numcolumns][counter - 1]; } else { temphist2 = new float[counter - 1][numcolumns]; } for (int k = 0; k < counter - 1; k++) { float[] temp = tab_delim2float(lines[k]); for (int j = 0; j < numcolumns; j++) { if (ch2green) { temphist2[j][k] = temp[j]; } else { temphist2[k][j] = temp[j]; } } } histograms[i] = temphist2; d.close(); } catch (IOException e) { showioerror(); return; } } for (int i = 0; i < nfiles; i++) { if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } } // note that here x is green and y is red float[][][] pch = new float[nfiles][xmax][ymax]; for (int i = 0; i < nfiles; i++) { for (int j = 0; j < ((float[][]) histograms[i]).length; j++) { for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) { pch[i][j][k] = ((float[][]) histograms[i])[j][k]; } } } final PCH2DFitWindow cw = new PCH2DFitWindow(); cw.init(names, pch, psfflag); final Frame f = new Frame("PCH 2D Analysis"); f.setLocation(10, 10); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.add(cw); f.pack(); f.setResizable(false); Insets ins = f.getInsets(); cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65; cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right; f.setSize(cw.totalSize); f.setVisible(true); cw.requestFocus(); }
private void geterrors() { GenericDialog gd = new GenericDialog("Options"); float conf = 0.67f; gd.addNumericField("Confidence Limit", (int) (conf * 100.0f), 5, 10, null); gd.addChoice("Error Parameter", paramsnames, paramsnames[0]); double spacing = 0.01; gd.addNumericField("Chi^2 plot spacing (% of value)?", spacing * 100.0, 2, 10, null); boolean globalerror = false; gd.addCheckbox("Global Fit Error?", globalerror); int dataset = 0; gd.addNumericField("Data Set (for Global Error)", dataset, 0); gd.showDialog(); if (gd.wasCanceled()) { return; } conf = 0.01f * (float) gd.getNextNumber(); int paramindex = (int) gd.getNextChoiceIndex(); spacing = 0.01 * gd.getNextNumber(); globalerror = gd.getNextBoolean(); dataset = (int) gd.getNextNumber(); if (globalerror) { support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, true, 0.1); int[] erindeces = {paramindex, dataset}; // need to set up all the matrices int nsel = 0; int nparams = 11; for (int i = 0; i < ncurves; i++) { if (include[i]) { nsel++; } } double[][] params = new double[nsel][nparams]; String[][] tempformulas = new String[nsel][nparams]; double[][][] constraints = new double[2][nsel][nparams]; int[][] vflmatrix = new int[nsel][nparams]; float[][] tempdata = new float[nsel][xpts * ypts]; float[][] tempweights = new float[nsel][xpts * ypts]; int nfit = 0; int counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < nparams; j++) { params[counter][j] = globalparams[i][j]; tempformulas[counter][j] = globalformulas[i][j]; constraints[0][counter][j] = globalconstraints[0][i][j]; constraints[1][counter][j] = globalconstraints[1][i][j]; vflmatrix[counter][j] = globalvflmatrix[i][j]; if (vflmatrix[counter][j] == 0 || (j == 0 && vflmatrix[counter][j] == 2)) { nfit++; } } for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { tempdata[counter][j + k * xpts] = (float) ((double) pch[i][j][k] / (double) nmeas[i]); tempweights[counter][j + k * xpts] = weights[i][j][k]; } } counter++; } } int dofnum = xpts * ypts * nsel - (nfit - 1) - 1; int dofden = xpts * ypts * nsel - nfit - 1; // double flim=FLimit(dofnum,dofden,(double)conf); double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf); IJ.log("FLimit = " + (float) flim); if (flim == Double.NaN && flim < 1.0) { IJ.showMessage("Invalid Limiting F Value"); return; } double truespacing = Math.abs(params[erindeces[1]][erindeces[0]] * spacing); double[][] c2plot = erclass.geterrorsglobal( params, vflmatrix, tempformulas, paramsnames, constraints, tempdata, tempweights, flim, truespacing, erindeces); IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]); int templength = c2plot[0].length; float[][] c2plotf = new float[2][templength - 1]; for (int i = 0; i < (templength - 1); i++) { c2plotf[0][i] = (float) c2plot[0][i + 1]; c2plotf[1][i] = (float) c2plot[1][i + 1]; } new PlotWindow4( "c2 plot", paramsnames[paramindex] + "[" + dataset + "]", "Chi^2", c2plotf[0], c2plotf[1]) .draw(); } else { support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, false, 0.1); int errindex = paramindex; float[] tempdata = new float[xpts * ypts]; float[] tempweights = new float[xpts * ypts]; for (int i = 0; i < xpts; i++) { for (int j = 0; j < ypts; j++) { tempdata[i + j * xpts] = (float) ((double) avg[i][j] / (double) nmeas[ncurves]); tempweights[i + j * xpts] = avgweights[i][j]; } } int nfit = 0; for (int i = 0; i < 7; i++) { if (avgfixes[i] == 0) { nfit++; } } int dofnum = xpts * ypts - (nfit - 1) - 1; int dofden = xpts * ypts - nfit - 1; double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf); IJ.log("FLimit = " + (float) flim); if (flim == Double.NaN && flim < 1.0) { IJ.showMessage("Invalid Limiting F Value"); return; } double truespacing = Math.abs(avgparams[errindex] * spacing); double[][] c2plot = erclass.geterrors( avgparams, avgfixes, avgconstraints, tempdata, tempweights, flim, truespacing, errindex); IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]); int templength = c2plot[0].length; float[][] c2plotf = new float[2][templength - 1]; for (int i = 0; i < (templength - 1); i++) { c2plotf[0][i] = (float) c2plot[0][i + 1]; c2plotf[1][i] = (float) c2plot[1][i + 1]; } new PlotWindow4("c2 plot", paramsnames[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw(); } }
public boolean get_errors(double[] params, int[] fixes) { GenericDialog gd = new GenericDialog("Error Options"); String[] methods = {"Support Plane", "Monte Carlo"}; gd.addChoice("Method", methods, methods[0]); float conf = 0.67f; gd.addNumericField("SP_Confidence Limit (%)", (int) (conf * 100.0f), 5, 10, null); String[] labels = {"P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10"}; gd.addChoice("SP_Parameter", labels, labels[0]); double spacing = 0.01; gd.addNumericField("SP_Chi^2_plot_spacing (% of value)?", spacing * 100.0, 2, 10, null); int ntrials = 100; gd.addNumericField("MC_#_Trials", ntrials, 0); gd.showDialog(); if (gd.wasCanceled()) { return false; } int methodindex = gd.getNextChoiceIndex(); conf = 0.01f * (float) gd.getNextNumber(); int paramindex = gd.getNextChoiceIndex(); spacing = 0.01 * gd.getNextNumber(); ntrials = (int) gd.getNextNumber(); if (methodindex == 0) { support_plane_errors_v2 erclass = new support_plane_errors_v2(this, 0.0001, 50, false, 0.1); int errindex = paramindex; int nfit = 0; for (int i = 0; i < labels.length; i++) { if (fixes[i] == 0) { nfit++; } } int npts = tempdata.length; int dofnum = npts - (nfit - 1) - 1; int dofden = npts - nfit - 1; double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf); IJ.log("FLimit = " + (float) flim); if (flim == Double.NaN && flim < 1.0) { IJ.showMessage("Invalid Limiting F Value"); return false; } double truespacing = Math.abs(params[errindex] * spacing); double[][] c2plot = erclass.geterrors( params, fixes, constraints, tempdata, weights, flim, truespacing, errindex); IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]); IJ.log( "upper error = " + (c2plot[1][0] - params[errindex]) + " lower error = " + (params[errindex] - c2plot[0][0])); int templength = c2plot[0].length; float[][] c2plotf = new float[2][templength - 1]; for (int i = 0; i < (templength - 1); i++) { c2plotf[0][i] = (float) c2plot[0][i + 1]; c2plotf[1][i] = (float) c2plot[1][i + 1]; } new PlotWindow4("c2 plot", labels[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw(); } else { StringBuffer sb = new StringBuffer(); sb.append("Trial\t"); for (int i = 0; i < labels.length; i++) { if (fixes[i] == 0) sb.append(labels[i] + "\t"); } sb.append("chi^2"); tw = new TextWindow("Monte Carlo Results", sb.toString(), "", 400, 400); redirect = true; monte_carlo_errors_v2 erclass = new monte_carlo_errors_v2(this, 0.0001, 50, false, 0.1); double[][] errors = erclass.geterrors(params, fixes, constraints, tempdata, weights, ntrials); sb = new StringBuffer(); sb.append("StDev\t"); for (int i = 0; i < errors.length; i++) { float[] ferr = new float[errors[0].length]; for (int j = 0; j < ferr.length; j++) ferr[j] = (float) errors[i][j]; float stdev = jstatistics.getstatistic("StDev", ferr, null); sb.append("" + stdev); if (i < (errors.length - 1)) sb.append("\t"); } tw.append(sb.toString()); redirect = false; } return true; }
public boolean analyseParticles(MyFunctions f) { GenericDialog gd = new GenericDialog("Analyse PALM/STORM Particles"); gd.addNumericField("Minimum SNR", prefs.get("QuickPALM.snr", 5), 2); gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.fwhm", 4), 0); gd.addNumericField("Image plane pixel size (nm)", prefs.get("QuickPALM.pixelsize", 106), 2); gd.addCheckbox("Smart SNR", prefs.get("QuickPALM.smartsnr", true)); gd.addCheckbox( "3D PALM (astigmatism) - will require calibration file", prefs.get("QuickPALM.is3d", false)); gd.addCheckbox("Online rendering", prefs.get("QuickPALM.view", true)); gd.addCheckbox("Attach to running acquisition", prefs.get("QuickPALM.attach", false)); gd.addCheckbox("Stream particle info directly into file", prefs.get("QuickPALM.stream", true)); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Online rendering settings (used only if selected) --"); gd.addMessage("\n"); gd.addNumericField("Pixel size of rendered image (nm)", 30, 2); gd.addNumericField("Accumulate last (0 to accumulate all frames)", 0, 0); gd.addNumericField("Update every (frames)", 10, 0); // gd.addNumericField("Allow color saturation (%)", 50, 0); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Attach to running acquisition settings (used only if selected) --"); gd.addMessage("\n"); gd.addStringField( "_Image name pattern (NN...NN represents the numerical change)", prefs.get("QuickPALM.pattern", "imgNNNNNNNNN.tif"), 20); gd.addNumericField("Start NN...NN with", 0, 0); gd.addNumericField("In acquisition max. wait time for new image (ms)", 50, 0); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Advanced settings (don't normally need to be changed) --"); gd.addMessage("\n"); gd.addNumericField("_Minimum symmetry (%)", prefs.get("QuickPALM.symmetry", 50), 0); gd.addNumericField( "Local threshold (% maximum intensity)", prefs.get("QuickPALM.lthreshold", 20), 0); gd.addNumericField("_Maximum iterations per frame", prefs.get("QuickPALM.maxiter", 1000), 0); gd.addNumericField( "Threads (each takes ~3*[frame size] in memory)", prefs.get("QuickPALM.nthreads", 50), 0); gd.addMessage("\n\nDon't forget to save the table in the end..."); gd.showDialog(); if (gd.wasCanceled()) return false; snr = (int) gd.getNextNumber(); prefs.set("QuickPALM.snr", snr); fwhm = gd.getNextNumber(); prefs.set("QuickPALM.fwhm", fwhm); pixelsize = gd.getNextNumber(); prefs.set("QuickPALM.pixelsize", pixelsize); smartsnr = gd.getNextBoolean(); prefs.set("QuickPALM.smartsnr", smartsnr); is3d = gd.getNextBoolean(); prefs.set("QuickPALM.is3d", is3d); view = gd.getNextBoolean(); prefs.set("QuickPALM.view", view); attach = gd.getNextBoolean(); prefs.set("QuickPALM.attach", attach); if (gd.getNextBoolean()) { f.psave = new ParticleSaver(); f.psave.setup(); prefs.set("QuickPALM.stream", true); } else prefs.set("QuickPALM.stream", false); // -- magn = pixelsize / gd.getNextNumber(); viewer_accumulate = (int) gd.getNextNumber(); viewer_update = (int) gd.getNextNumber(); // -- pattern = gd.getNextString().trim(); prefs.set("QuickPALM.pattern", pattern); prefix = pattern.substring(0, pattern.indexOf("N")); sufix = pattern.substring(pattern.lastIndexOf("N") + 1, pattern.length()); nimchars = pattern.split("N").length - 1; nimstart = (int) gd.getNextNumber(); waittime = (int) gd.getNextNumber(); // -- symmetry = gd.getNextNumber() / 100; prefs.set("QuickPALM.symmetry", symmetry); pthrsh = gd.getNextNumber() / 100; prefs.set("QuickPALM.lthreshold", pthrsh * 100); maxpart = (int) gd.getNextNumber(); prefs.set("QuickPALM.maxiter", maxpart); threads = (int) gd.getNextNumber(); prefs.set("QuickPALM.nthreads", threads); return true; }
public boolean reconstructDataset() { view_modes[0] = "3D color"; view_modes[1] = "2D histogram"; view_modes[2] = "2D particle intensity (16-bit)"; view_modes[3] = "2D particle intensity (8-bit)"; GenericDialog gd = new GenericDialog("Reconstruct PALM/STORM Dataset"); gd.addNumericField( "Target pixel size for the rendered image (nm)", prefs.get("QuickPALM.viewer_tpixelsize", 30), 2); gd.addNumericField("Original image width (px)", prefs.get("QuickPALM.viewer_owidth", 512), 2); gd.addNumericField("Original image height (px)", prefs.get("QuickPALM.viewer_oheight", 512), 2); gd.addChoice("View mode", view_modes, prefs.get("QuickPALM.view_mode", view_modes[1])); // gd.addNumericField("Allow image saturation (%)", prefs.get("QuickPALM.saturation", 50), 0); gd.addCheckbox( "Simulate sub-difraction spot (gaussian convolution - only 2D)", prefs.get("QuickPALM.viewer_doConvolve", true)); // gd.addCheckbox("Make 3D stack", prefs.get("QuickPALM.viewer_do3d", false)); // gd.addCheckbox("Make movie", prefs.get("QuickPALM.viewer_doMovie", false)); gd.addCheckbox("Make 3D stack", false); gd.addCheckbox("Make movie", false); // gd.addCheckbox("Save only and don't show", prefs.get("QuickPALM.viewer_doSave", false)); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Simulate sub-difraction spot settings (used only if selected) --"); gd.addNumericField("FWHM of the spot", prefs.get("QuickPALM.viewer_fwhm", 30), 2); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Make 3D stack settings (used only if selected) --"); gd.addNumericField("Z-spacing between slices (nm)", prefs.get("QuickPALM.viewer_zstep", 50), 2); gd.addNumericField( "Merge particle Z-position above (nm - 0 for full Z range)", prefs.get("QuickPALM.viewer_mergeabove", 0), 2); gd.addNumericField( "Merge particle Z-position bellow (nm - 0 for full Z range)", prefs.get("QuickPALM.viewer_mergebellow", 0), 2); gd.addMessage("\n"); // ----------------------------------------- gd.addMessage("-- Make movie settings (used only if selected) --"); gd.addNumericField( "Make a reconstruction in every N frames", prefs.get("QuickPALM.viewer_update", 10), 0); gd.addNumericField( "Accumulate N neighboring frames for each reconstruction\n(set to 0 to accumulate all the preceding frames)", prefs.get("QuickPALM.viewer_accumulate", 100), 0); gd.showDialog(); if (gd.wasCanceled()) return false; viewer_tpixelsize = gd.getNextNumber(); prefs.set("QuickPALM.viewer_tpixelsize", viewer_tpixelsize); viewer_owidth = (int) gd.getNextNumber(); prefs.set("QuickPALM.viewer_owidth", viewer_owidth); viewer_oheight = (int) gd.getNextNumber(); prefs.set("QuickPALM.viewer_oheight", viewer_oheight); view_mode = gd.getNextChoice(); prefs.set("QuickPALM.view_mode", view_mode); viewer_doConvolve = gd.getNextBoolean(); prefs.set("QuickPALM.viewer_doConvolve", viewer_doConvolve); viewer_do3d = gd.getNextBoolean(); prefs.set("QuickPALM.viewer_do3d", viewer_do3d); viewer_doMovie = gd.getNextBoolean(); prefs.set("QuickPALM.viewer_doMovie", viewer_doMovie); // viewer_doSave = gd.getNextBoolean(); // prefs.set("QuickPALM.viewer_doSave", viewer_doSave); // -- Simulate sub-difraction spot viewer_fwhm = gd.getNextNumber(); prefs.set("QuickPALM.viewer_fwhm", viewer_fwhm); // -- Show B&W // viewer_is8bit = gd.getNextBoolean(); // prefs.set("QuickPALM.viewer_is8bit", viewer_is8bit); // -- Make 3D stack viewer_zstep = gd.getNextNumber(); prefs.set("QuickPALM.viewer_zstep", viewer_zstep); viewer_mergeabove = gd.getNextNumber(); prefs.set("QuickPALM.viewer_mergeabove", viewer_mergeabove); viewer_mergebellow = gd.getNextNumber(); prefs.set("QuickPALM.viewer_mergebellow", viewer_mergebellow); // -- Make Movie viewer_update = (int) gd.getNextNumber(); prefs.set("QuickPALM.viewer_update", viewer_update); viewer_accumulate = (int) gd.getNextNumber(); prefs.set("QuickPALM.viewer_accumulate", viewer_accumulate); return true; }
public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); Calibration cal = imp.getCalibration(); GenericDialog gd = new GenericDialog("Options"); int subsize = 32; gd.addNumericField("Subregion Size (pixels)?", subsize, 0); int stepsize = 16; gd.addNumericField("Step Size?", stepsize, 0); int shift = 3; gd.addNumericField("STICS temporal Shift?", shift, 0); float xoffset = 0.0f; gd.addNumericField("X_Offset", xoffset, 5, 15, null); float yoffset = 0.0f; gd.addNumericField("Y_Offset", yoffset, 5, 15, null); float multiplier = 8.0f; gd.addNumericField("Velocity Multiplier", multiplier, 5, 15, null); float ftime = 1.0f; gd.addNumericField("Frame_Time(min)", ftime, 5, 15, null); float scaling = (float) cal.pixelWidth; gd.addNumericField("Pixel_Size(um)", scaling, 5, 15, null); boolean norm = true; gd.addCheckbox("Normalize_Vector_lengths?", norm); boolean centered = true; gd.addCheckbox("Center_Vectors?", centered); float magthresh = 0.0f; gd.addNumericField("Magnitude_Threshhold?", magthresh, 5, 15, null); int rlength = 10; gd.addNumericField("Running_avg_length", rlength, 0); int inc = 5; gd.addNumericField("Start_frame_increment", inc, 0); gd.showDialog(); if (gd.wasCanceled()) { return; } subsize = (int) gd.getNextNumber(); stepsize = (int) gd.getNextNumber(); shift = (int) gd.getNextNumber(); xoffset = (float) gd.getNextNumber(); yoffset = (float) gd.getNextNumber(); multiplier = (float) gd.getNextNumber(); ftime = (float) gd.getNextNumber(); scaling = (float) gd.getNextNumber(); norm = gd.getNextBoolean(); centered = gd.getNextBoolean(); magthresh = (float) gd.getNextNumber(); rlength = (int) gd.getNextNumber(); inc = (int) gd.getNextNumber(); int width = imp.getWidth(); int xregions = 1 + (int) (((float) width - (float) subsize) / (float) stepsize); int newwidth = xregions * subsize; int height = imp.getHeight(); int yregions = 1 + (int) (((float) height - (float) subsize) / (float) stepsize); int newheight = yregions * subsize; ImageStack stack = imp.getStack(); int slices = imp.getNSlices(); int channels = imp.getNChannels(); int frames = imp.getNFrames(); if (frames == 1) { frames = slices; slices = 1; } Roi roi = imp.getRoi(); if (roi == null) { roi = new Roi(0, 0, width, height); } STICS_map map = new STICS_map(subsize, stepsize); Object[] tseries = jutils.get3DTSeries(stack, 0, 0, frames, slices, channels); map.update_STICS_map(tseries, width, height, 0, rlength, roi.getPolygon(), shift); FloatProcessor fp = map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh); ImageStack vector_stack = new ImageStack(fp.getWidth(), fp.getHeight()); vector_stack.addSlice("", fp); float[][] vel = map.get_scaled_velocities(scaling, ftime, stepsize); ImageStack velstack = new ImageStack(map.xregions, map.yregions); velstack.addSlice("", vel[0]); velstack.addSlice("", vel[1]); int velframes = 2; IJ.showStatus("frame " + 0 + " calculated"); for (int i = inc; i < (frames - rlength); i += inc) { map.update_STICS_map(tseries, width, height, i, rlength, roi.getPolygon(), shift); FloatProcessor fp2 = map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh); vector_stack.addSlice("", fp2); vel = map.get_scaled_velocities(scaling, ftime, stepsize); velstack.addSlice("", vel[0]); velstack.addSlice("", vel[1]); velframes += 2; IJ.showStatus("frame " + i + " calculated"); } (new ImagePlus("STICS Vectors", vector_stack)).show(); ImagePlus imp3 = new ImagePlus("Velocities", velstack); imp3.setOpenAsHyperStack(true); imp3.setDimensions(2, 1, velframes / 2); new CompositeImage(imp3, CompositeImage.COLOR).show(); }
public void run(String arg) { String[] labels = { "Masked_Chromosomes", "Unmixed_Image", "Spectral_Image(optional)", "Spectra(optional)" }; ImagePlus[] imps = jutils.selectImages(true, 4, labels); if (imps == null) { return; } if (imps[0] == null) { return; } float[] mask = (float[]) imps[0].getStack().getPixels(2); findblobs3 fb = new findblobs3(imps[0].getWidth(), imps[0].getHeight()); float[] objects = fb.dofindblobs(mask, 0.5f); WaitForUserDialog dg = new WaitForUserDialog( "Optional Input", "Place RoiManager Points on Chromosome Segments (if desired)"); dg.show(); if (!dg.escPressed()) { RoiManager rman = RoiManager.getInstance(); while (rman != null && rman.getCount() > 1) { Roi[] rois = rman.getRoisAsArray(); int[] ids = new int[rois.length]; for (int i = 0; i < rois.length; i++) { Rectangle r = rois[i].getBounds(); ids[i] = (int) objects[r.x + fb.width * r.y]; } objects = fb.link_objects(objects, ids); rman.reset(); dg = new WaitForUserDialog( "Optional Input", "Place More RoiManager Points on Chromosome Segments (if desired)"); dg.show(); if (dg.escPressed()) break; } } int[] areas = fb.get_areas(objects); int[] temprank = jsort.get_javasort_order(areas); int[] arearank = jsort.get_javasort_order(temprank); for (int i = 0; i < fb.nobjects; i++) { arearank[i] = fb.nobjects - arearank[i] - 1; } // if the spectra are available, get them float[][][] spectra = null; Object[] data = null; if (imps[1] != null && imps[2] != null && imps[3] != null) { ImageWindow iw = imps[3].getWindow(); if (iw.getClass().getName().equals("jguis.PlotWindow4")) { float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); data = jutils.stack2array(imps[2].getStack()); Object[] coef = jutils.stack2array(imps[1].getStack()); spectra = new float[fb.nobjects][2][]; for (int i = 0; i < fb.nobjects; i++) { spectra[i][0] = fb.get_object_spectrum(objects, (i + 1), data, "Sum"); spectra[i][1] = new float[yvals[0].length]; float[] tempcoef = fb.get_object_spectrum(objects, (i + 1), coef, "Sum"); for (int j = 0; j < yvals[0].length; j++) { for (int k = 0; k < 5; k++) { spectra[i][1][j] += tempcoef[k] * yvals[k][j]; } } } } } CompositeImage imp = (CompositeImage) imps[0]; imp.setPosition(1, 1, 1); LUT graylut = jutils.get_lut_for_color(Color.white); imp.setChannelColorModel(graylut); imp.setPosition(2, 1, 1); LUT redlut = jutils.get_lut_for_color(Color.red); imp.setChannelColorModel(redlut); imp.setPosition(1, 1, 1); imp.updateAndRepaintWindow(); SkyPanel_v3 sp = new SkyPanel_v3(); int skychan = 6; if (imps[1] != null) skychan = imps[1].getNChannels(); // assume that the sky image has 6 channels and that the second is the unknown green // shift the unknown green to the end ImagePlus skyimp = null; if (imps[1] != null) { Object[] skystack = jutils.stack2array(imps[1].getStack()); // Object[] // skystack2={skystack[0],skystack[2],skystack[3],skystack[4],skystack[5],skystack[1]}; Object[] skystack2 = null; if (skychan == 6) skystack2 = new Object[] {skystack[0], skystack[2], skystack[3], skystack[4], skystack[5]}; else skystack2 = new Object[] {skystack[0], skystack[1], skystack[2], skystack[3], skystack[4]}; skyimp = new ImagePlus( "rearranged", jutils.array2stack(skystack2, imps[1].getWidth(), imps[1].getHeight())); } int nch = 5; if (skyimp != null) nch = skyimp.getStack().getSize(); GenericDialog gd2 = new GenericDialog("Options"); gd2.addNumericField("Area Accuracy (percent)", 30, 0); for (int i = 0; i < nch; i++) { gd2.addNumericField("Ch_" + (i + 1) + "_Contr_Thresh", 0.35, 5, 15, null); } // gd2.addNumericField("Contribution Threshold",0.35,5,15,null); gd2.addCheckbox("Mouse?", false); gd2.addNumericField("Box_Width", 150, 0); gd2.addNumericField("Box_Height", 100, 0); gd2.showDialog(); if (gd2.wasCanceled()) { return; } sp.areathresh = (float) gd2.getNextNumber(); sp.objthresh2 = new float[nch]; for (int i = 0; i < nch; i++) sp.objthresh2[i] = (float) gd2.getNextNumber(); // sp.objthresh=(float)gd2.getNextNumber(); boolean mouse = gd2.getNextBoolean(); int bwidth = (int) gd2.getNextNumber(); int bheight = (int) gd2.getNextNumber(); int[] colorindices = {4, 1, 2, 6, 3}; GenericDialog gd3 = new GenericDialog("Color Options"); for (int i = 0; i < 5; i++) gd3.addChoice( "Ch" + (i + 1) + " Color", SkyPanel_v3.colornames, SkyPanel_v3.colornames[colorindices[i]]); gd3.showDialog(); if (gd3.wasCanceled()) return; for (int i = 0; i < 5; i++) colorindices[i] = gd3.getNextChoiceIndex(); sp.colorindices = colorindices; sp.nch = 5; sp.dapilast = false; sp.cellwidth = bwidth; sp.cellheight = bheight; sp.init(imps[0], skyimp, objects, areas, arearank, fb, true, spectra, data, mouse); SkyPanel_v3.launch_frame(sp); }