/** * Get the index of the closest downsample factor from an array of available factors. * * The array is assumed to be sorted in ascending order. * * @param preferredDownsamples * @param downsampleFactor * @return */ public static int getClosestDownsampleIndex(double[] preferredDownsamples, double downsampleFactor) { downsampleFactor = Math.max(downsampleFactor, 1.0); int bestDownsampleSeries = -1; double bestDownsampleDiff = Double.POSITIVE_INFINITY; for (int i = 0; i < preferredDownsamples.length; i++) { double downsampleDiff = downsampleFactor - preferredDownsamples[i]; if (!Double.isNaN(downsampleDiff) && (downsampleDiff >= 0 || GeneralTools.almostTheSame(downsampleFactor, preferredDownsamples[i], 0.01)) && downsampleDiff < bestDownsampleDiff) { bestDownsampleSeries = i; bestDownsampleDiff = Math.abs(downsampleDiff); } } return bestDownsampleSeries; }
/** * Format a value with a maximum number of decimal places, using the default Locale. * * @param value * @param nDecimalPlaces * @return */ public synchronized static String formatNumber(final double value, final int maxDecimalPlaces) { return formatNumber(Locale.getDefault(Category.FORMAT), value, maxDecimalPlaces); }
@Override public Map<String, ?> getParameterMap() { if (arg == null || arg.trim().length() == 0) return Collections.emptyMap(); // Try to parse as an argument string try { return GeneralTools.parseArgStringValues(arg); } catch (Exception e) { return Collections.singletonMap("Argument", arg); } }
static String getDiameterString(final ImageServer<BufferedImage> server, final ParameterList params) { if (server.hasPixelSizeMicrons()) return String.format("%.1f %s", params.getDoubleParameterValue("tileSizeMicrons"), GeneralTools.micrometerSymbol()); else return String.format("%d px", (int)(params.getDoubleParameterValue("tileSizePx") + .5)); }
if (server != null && server.hasPixelSizeMicrons()) { fwhm = getParameterList(imageData).getDoubleParameterValue("fwhmMicrons"); fwhmStringTemp = GeneralTools.createFormatter(2).format(fwhm) + " " + GeneralTools.micrometerSymbol(); fwhm /= server.getAveragedPixelSizeMicrons(); fwhmStringTemp = GeneralTools.createFormatter(2).format(fwhm) + " px";
@Override public void addMeasurements(PathObject pathObject, String name, ParameterList params) { // Check if we have a median we can use if (histogram == null || histogram.length == 0) return; // Start from the end & update double total = 0; double[] proportions = new double[histogram.length]; for (int i = histogram.length-1; i >= 0; i--) { total += histogram[i] / (double)n; proportions[i] = total; } // Add the measurements MeasurementList measurementList = pathObject.getMeasurementList(); double binWidth = (maxBin - minBin) / (nBins - 1); NumberFormat formatter = GeneralTools.createFormatter(3); for (int i = 0; i < histogram.length; i++) { double value = minBin + i * binWidth; measurementList.putMeasurement(name + " >= " + formatter.format(value), proportions[i]); } }
public String arrayAsString(final Locale locale, final String delimiter, final int nDecimalPlaces) { return GeneralTools.arrayToString(locale, new double[]{r, g, b}, delimiter, nDecimalPlaces); // return String.format( "%.Nf%s%.Nf%s%.Nf".replace("N", Integer.toString(nDecimalPlaces)), r, delimiter, g, delimiter, b); // return String.format( "%.Nf, %.Nf, %.Nf".replace("N", Integer.toString(nDecimalPlaces)), r, g, b ); // return String.format( "[%.Nf, %.Nf, %.Nf]".replace("N", Integer.toString(nDecimalPlaces)), r, g, b ); // return "[" + IJ.d2s(r, nDecimalPlaces) + ", " + IJ.d2s(g, nDecimalPlaces) + ", " + IJ.d2s(b, nDecimalPlaces) + "]"; }
/** * Create a workflow step to run a classifier. * * @param name * @param classifierPath */ public RunSavedClassifierWorkflowStep(final String name, final String classifierPath) { this.name = name; this.classifierPath = GeneralTools.escapeFilePath(classifierPath); }
@Override public boolean isValid() { return !GeneralTools.blankString(intensityMeasurement, true) && !Double.isNaN(t1); }
String questionChar = GeneralTools.isWindows() ? "" : "?"; Path cachePath = fileSystem.getPath(cacheRootPath, url.replace("://", File.separator).replace(":/", File.separator).replace("?", questionChar+File.separator));
static String getDiameterString(final ImageServer<BufferedImage> server, final ParameterList params) { if (server.hasPixelSizeMicrons()) return String.format("%.1f %s", params.getDoubleParameterValue("tileSizeMicrons"), GeneralTools.micrometerSymbol()); else return String.format("%d px", (int)(params.getDoubleParameterValue("tileSizePx") + .5)); }
/** * Convert a double array to a String using a space as a delimiter. * * @param locale * @param array * @param nDecimalPlaces * @return */ public static String arrayToString(final Locale locale, final double[] array, final int nDecimalPlaces) { return arrayToString(locale, array, " ", nDecimalPlaces); }
@Override public boolean validateSquarePixels() { return GeneralTools.almostTheSame(getPixelWidthMicrons(), getPixelHeightMicrons(), 0.0001); }
static String getDiameterString(final ImageServer<BufferedImage> server, final ParameterList params) { if (server.hasPixelSizeMicrons()) return String.format("%.1f %s", params.getDoubleParameterValue("tileSizeMicrons"), GeneralTools.micrometerSymbol()); else return String.format("%d px", (int)(params.getDoubleParameterValue("tileSizePx") + .5)); }
@Override public Map<String, ?> getParameterMap() { if (arg == null || arg.trim().length() == 0) return Collections.emptyMap(); // Try to parse as an argument string try { return GeneralTools.parseArgStringValues(arg); } catch (Exception e) { return Collections.singletonMap("Argument", arg); } }
public String getResultString() { if (Double.isNaN(pValue)) return "-"; String pValueString; int maxDecimalPlaces; if (pValue > 1e-3) maxDecimalPlaces = 4; else if (pValue > 1e-4) maxDecimalPlaces = 5; else if (pValue > 1e-5) maxDecimalPlaces = 6; else if (pValue > 1e-6) maxDecimalPlaces = 7; else maxDecimalPlaces = 8; // } pValueString = GeneralTools.formatNumber(pValue, maxDecimalPlaces); return String.format("%s (%.2f; %.2f-%.2f)", pValueString, hazardRatio, hazardRatioLowerConfidence, hazardRatioUpperConfidence); }
public String arrayAsString(final Locale locale, final int nDecimalPlaces) { return GeneralTools.arrayToString(locale, new double[]{r, g, b}, nDecimalPlaces); // return String.format( "%.Nf %.Nf %.Nf".replace("N", Integer.toString(nDecimalPlaces)), r, g, b ); // return String.format( "%.Nf, %.Nf, %.Nf".replace("N", Integer.toString(nDecimalPlaces)), r, g, b ); // return String.format( "[%.Nf, %.Nf, %.Nf]".replace("N", Integer.toString(nDecimalPlaces)), r, g, b ); // return "[" + IJ.d2s(r, nDecimalPlaces) + ", " + IJ.d2s(g, nDecimalPlaces) + ", " + IJ.d2s(b, nDecimalPlaces) + "]"; }
public boolean isCircle(double pixelWidth, double pixelHeight) { return GeneralTools.almostTheSame(getBoundsWidth() * pixelWidth, getBoundsHeight() * pixelHeight, 0.00001); }
public TilerPlugin() { // Set up initial parameters params = new ParameterList(); params.addTitleParameter("Tile options"); params.addDoubleParameter("tileSizeMicrons", "Tile size", 100, GeneralTools.micrometerSymbol(), "Specify tile width and height, in " + GeneralTools.micrometerSymbol()); params.addDoubleParameter("tileSizePx", "Tile size", 200, "px", "Specify tile width and height, in pixels"); params.addBooleanParameter("trimToROI", "Trim to ROI", true, "Trim tiles to match the parent ROI shape, rather than overlap boundaries with full squares"); params.addTitleParameter("Annotation options"); params.addBooleanParameter("makeAnnotations", "Make annotation tiles", false, "Create annotation objects, rather than tile objects"); params.addBooleanParameter("removeParentAnnotation", "Remove parent annotation", false, "Remove the parent object, if it was an annotation; has no effect if 'Make annotation tiles' is not selected, or the parent object is not an annotation"); }
@Override protected boolean parseArgument(ImageData<T> imageData, String arg) { if (arg != null) { logger.trace("Updating parameters with arg: {}", arg); // Parse JSON-style arguments Map<String, String> map = GeneralTools.parseArgStringValues(arg); params = getParameterList(imageData); // Use US locale for standardization, and use of decimal points (not commas) ParameterList.updateParameterList(params, map, Locale.US); } return imageData != null; }