/** Converts the given reader into a MinMaxCalculator, wrapping if needed. */ public static MinMaxCalculator makeMinMaxCalculator(IFormatReader r) { if (r instanceof MinMaxCalculator) return (MinMaxCalculator) r; return new MinMaxCalculator(r); }
public void initPreMinMaxValues() throws FormatException, IOException { // get a priori min/max values preGlobalMin = preGlobalMax = null; preKnownMin = preKnownMax = null; prePlaneMin = prePlaneMax = null; preIsMinMaxPop = false; if (minmax) { int sizeC = reader.getSizeC(); preGlobalMin = new Double[sizeC]; preGlobalMax = new Double[sizeC]; preKnownMin = new Double[sizeC]; preKnownMax = new Double[sizeC]; for (int c=0; c<sizeC; c++) { preGlobalMin[c] = minMaxCalc.getChannelGlobalMinimum(c); preGlobalMax[c] = minMaxCalc.getChannelGlobalMaximum(c); preKnownMin[c] = minMaxCalc.getChannelKnownMinimum(c); preKnownMax[c] = minMaxCalc.getChannelKnownMaximum(c); } prePlaneMin = minMaxCalc.getPlaneMinimum(0); prePlaneMax = minMaxCalc.getPlaneMaximum(0); preIsMinMaxPop = minMaxCalc.isMinMaxPopulated(); } }
public void close() throws IOException { minMaxSet = null; super.close(false); }
/** * Returns true if the values returned by * getChannelGlobalMinimum/Maximum can be trusted. * * @throws FormatException Not actually thrown. * @throws IOException Not actually thrown. */ public boolean isMinMaxPopulated() throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); return minMaxDone != null && minMaxDone[getCoreIndex()] == getImageCount(); }
/** * Retrieves the specified channel's minimum based on the images that have * been read. Returns null if no image planes have been read yet. * * @throws FormatException Not actually thrown. * @throws IOException Not actually thrown. */ public Double getChannelKnownMinimum(int theC) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); return chanMin == null ? null : new Double(chanMin[getCoreIndex()][theC]); }
/** * Checks that the min and max values for each core index do not change * when the resolutions are unflattened. */ @Test public void testMultipleResolutions() throws Exception { minMaxCalculator.setCoreIndex(0); minMaxCalculator.openBytes(0); assertMinMax(-2.0, 101.0); minMaxCalculator.setCoreIndex(1); minMaxCalculator.openBytes(0); assertMinMax(-1.0, 102.0); MinMaxCalculator unflattened = new MinMaxCalculator(new MinMaxCalculatorTestReader()); try { unflattened.setFlattenedResolutions(false); unflattened.setId(TEST_FILE); unflattened.setCoreIndex(0); unflattened.openBytes(0); assertEquals(-2.0, unflattened.getPlaneMinimum(0)[0]); assertEquals(103.0, unflattened.getPlaneMaximum(0)[0]); unflattened.setCoreIndex(1); unflattened.openBytes(0); assertEquals(-1.0, unflattened.getPlaneMinimum(0)[0]); assertEquals(104.0, unflattened.getPlaneMaximum(0)[0]); } finally { unflattened.close(); } }
initMinMax(); int numRGB = getRGBChannelCount(); int series = getCoreIndex(); int pixelType = getPixelType(); int bpp = FormatTools.getBytesPerPixel(pixelType); int planeSize = getSizeX() * getSizeY() * bpp; && !Double.isNaN(planeMin[series][no * numRGB])) return; boolean little = isLittleEndian(); boolean interleaved = isInterleaved(); int[] coords = getZCTCoords(no); int cBase = coords[1] * numRGB; int pBase = no * numRGB; if (minMaxDone[getCoreIndex()] == getImageCount() && minMaxStore != null) { for (int c=0; c<getSizeC(); c++) { minMaxStore.setChannelGlobalMinMax(c, chanMin[getCoreIndex()][c], chanMax[getCoreIndex()][c], getSeries());
Double cMinVal = null, cMaxVal = null; try { cMinVal = minMaxCalc.getChannelGlobalMinimum(cIndex); cMaxVal = minMaxCalc.getChannelGlobalMaximum(cIndex); cMinVal = minMaxCalc.getChannelKnownMinimum(cIndex); cMaxVal = minMaxCalc.getChannelKnownMaximum(cIndex);
/** * Helper method to properly log any exceptions raised by Bio-Formats and * add a min/max calculator wrapper to the reader stack. * @param filePath Non-null. * @param series series to use * @param store Min/max store to use with the min/max calculator. */ protected BfPixelBuffer createMinMaxBfPixelBuffer(final String filePath, final int series, final IMinMaxStore store) { try { IFormatReader reader = createBfReader(); MinMaxCalculator calculator = new MinMaxCalculator(reader); calculator.setMinMaxStore(store); BfPixelBuffer pixelBuffer = new BfPixelBuffer(filePath, calculator); pixelBuffer.setSeries(series); log.info(String.format("Creating BfPixelBuffer: %s Series: %d", filePath, series)); return pixelBuffer; } catch (Exception e) { String msg = "Error instantiating pixel buffer: " + filePath; log.error(msg, e); throw new ResourceError(msg); } }
int seriesCount = unwrap().getCoreMetadataList().size(); int oldSeries = getCoreIndex(); setCoreIndex(i); chanMin[i] = new double[getSizeC()]; Arrays.fill(chanMin[i], Double.POSITIVE_INFINITY); setCoreIndex(oldSeries); setCoreIndex(i); chanMax[i] = new double[getSizeC()]; Arrays.fill(chanMax[i], Double.NEGATIVE_INFINITY); setCoreIndex(oldSeries); setCoreIndex(i); int numRGB = getRGBChannelCount(); planeMin[i] = new double[getImageCount() * numRGB]; Arrays.fill(planeMin[i], Double.NaN); setCoreIndex(oldSeries); setCoreIndex(i); int numRGB = getRGBChannelCount(); planeMax[i] = new double[getImageCount() * numRGB]; Arrays.fill(planeMax[i], Double.NaN); setCoreIndex(oldSeries);
/** * Retrieves a specified channel's global minimum. * Returns null if some of the image planes have not been read. * * @throws IOException Not actually thrown. */ public Double getChannelGlobalMinimum(int theC) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); if (theC < 0 || theC >= getSizeC()) { throw new FormatException("Invalid channel index: " + theC); } int series = getCoreIndex(); // check that all planes have been read if (minMaxDone == null || minMaxDone[series] < getImageCount()) { return null; } return new Double(chanMin[series][theC]); }
/** * Retrieves the maximum pixel value for the specified plane. * If each image plane contains more than one channel (i.e., * {@link #getRGBChannelCount()} > 1), returns the maximum value for each * embedded channel. Returns null if the plane has not already been read. * * @throws FormatException Not actually thrown. * @throws IOException Not actually thrown. */ public Double[] getPlaneMaximum(int no) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); if (planeMax == null) return null; int numRGB = getRGBChannelCount(); int pBase = no * numRGB; int series = getCoreIndex(); if (Double.isNaN(planeMax[series][pBase])) return null; Double[] max = new Double[numRGB]; for (int c=0; c<numRGB; c++) { max[c] = new Double(planeMax[series][pBase + c]); } return max; }
Double max = null; Double[] planeMin = minMax.getPlaneMinimum(index); Double[] planeMax = minMax.getPlaneMaximum(index);
initMinMax(); int numRGB = getRGBChannelCount(); int series = getCoreIndex(); int pixelType = getPixelType(); int bpp = FormatTools.getBytesPerPixel(pixelType); int planeSize = getSizeX() * getSizeY() * bpp; && !Double.isNaN(planeMin[series][no * numRGB])) return; boolean little = isLittleEndian(); boolean interleaved = isInterleaved(); int[] coords = getZCTCoords(no); int cBase = coords[1] * numRGB; int pBase = no * numRGB; if (minMaxDone[getCoreIndex()] == getImageCount() && minMaxStore != null) { for (int c=0; c<getSizeC(); c++) { minMaxStore.setChannelGlobalMinMax(c, chanMin[getCoreIndex()][c], chanMax[getCoreIndex()][c], getSeries());
Double cMinVal = null, cMaxVal = null; try { cMinVal = minMaxCalc.getChannelGlobalMinimum(cIndex); cMaxVal = minMaxCalc.getChannelGlobalMaximum(cIndex); cMinVal = minMaxCalc.getChannelKnownMinimum(cIndex); cMaxVal = minMaxCalc.getChannelKnownMaximum(cIndex);
@BeforeMethod public void setUp() throws Exception { fullPlaneCallIndex = 1; Location.mapId(TEST_FILE, TEST_FILE); reader = new MinMaxCalculatorTestReader(); reader.setId(TEST_FILE); minMaxStore = new TestMinMaxStore(); minMaxCalculator = new MinMaxCalculator(reader); minMaxCalculator.setMinMaxStore(minMaxStore); sizeX = reader.getSizeX(); sizeY = reader.getSizeY(); bpp = FormatTools.getBytesPerPixel(reader.getPixelType()); planeSize = sizeY * sizeY * bpp; }
int seriesCount = unwrap().getCoreMetadataList().size(); int oldSeries = getCoreIndex(); setCoreIndex(i); chanMin[i] = new double[getSizeC()]; Arrays.fill(chanMin[i], Double.POSITIVE_INFINITY); setCoreIndex(oldSeries); setCoreIndex(i); chanMax[i] = new double[getSizeC()]; Arrays.fill(chanMax[i], Double.NEGATIVE_INFINITY); setCoreIndex(oldSeries); setCoreIndex(i); int numRGB = getRGBChannelCount(); planeMin[i] = new double[getImageCount() * numRGB]; Arrays.fill(planeMin[i], Double.NaN); setCoreIndex(oldSeries); setCoreIndex(i); int numRGB = getRGBChannelCount(); planeMax[i] = new double[getImageCount() * numRGB]; Arrays.fill(planeMax[i], Double.NaN); setCoreIndex(oldSeries);
/** * Retrieves a specified channel's global maximum. * Returns null if some of the image planes have not been read. * @throws IOException Not actually thrown. */ public Double getChannelGlobalMaximum(int theC) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); if (theC < 0 || theC >= getSizeC()) { throw new FormatException("Invalid channel index: " + theC); } int series = getCoreIndex(); // check that all planes have been read if (minMaxDone == null || minMaxDone[series] < getImageCount()) { return null; } return new Double(chanMax[series][theC]); }
/** * Retrieves the minimum pixel value for the specified plane. * If each image plane contains more than one channel (i.e., * {@link #getRGBChannelCount()} > 1), returns the maximum value for each * embedded channel. Returns null if the plane has not already been read. * * @throws FormatException Not actually thrown. * @throws IOException Not actually thrown. */ public Double[] getPlaneMinimum(int no) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); if (planeMin == null) return null; int numRGB = getRGBChannelCount(); int pBase = no * numRGB; int series = getCoreIndex(); if (Double.isNaN(planeMin[series][pBase])) return null; Double[] min = new Double[numRGB]; for (int c=0; c<numRGB; c++) { min[c] = new Double(planeMin[series][pBase + c]); } return min; }
/** * Retrieves the specified channel's maximum based on the images that * have been read. Returns null if no image planes have been read yet. * * @throws FormatException Not actually thrown. * @throws IOException Not actually thrown. */ public Double getChannelKnownMaximum(int theC) throws FormatException, IOException { FormatTools.assertId(getCurrentFile(), true, 2); return chanMax == null ? null : new Double(chanMax[getCoreIndex()][theC]); }