Search in sources :

Example 1 with MinMaxCalculator

use of loci.formats.MinMaxCalculator in project bioformats by openmicroscopy.

the class Colorizer method applyDisplayRanges.

// -- Helper methods --
private void applyDisplayRanges(ImagePlus imp, int series) {
    if (imp instanceof VirtualImagePlus) {
        // virtual stacks handle their own display ranges
        return;
    }
    final ImporterOptions options = process.getOptions();
    final ImageProcessorReader reader = process.getReader();
    final int pixelType = reader.getPixelType();
    final boolean autoscale = options.isAutoscale() || // always autoscale float data
    FormatTools.isFloatingPoint(pixelType);
    final int cSize = imp.getNChannels();
    final double[] cMin = new double[cSize];
    final double[] cMax = new double[cSize];
    Arrays.fill(cMin, Double.NaN);
    Arrays.fill(cMax, Double.NaN);
    if (autoscale) {
        // extract display ranges for autoscaling
        final MinMaxCalculator minMaxCalc = process.getMinMaxCalculator();
        final int cBegin = process.getCBegin(series);
        final int cStep = process.getCStep(series);
        for (int c = 0; c < cSize; c++) {
            final int cIndex = cBegin + c * cStep;
            Double cMinVal = null, cMaxVal = null;
            try {
                cMinVal = minMaxCalc.getChannelGlobalMinimum(cIndex);
                cMaxVal = minMaxCalc.getChannelGlobalMaximum(cIndex);
                if (cMinVal == null) {
                    cMinVal = minMaxCalc.getChannelKnownMinimum(cIndex);
                }
                if (cMaxVal == null) {
                    cMaxVal = minMaxCalc.getChannelKnownMaximum(cIndex);
                }
            } catch (FormatException exc) {
            } catch (IOException exc) {
            }
            if (cMinVal != null)
                cMin[c] = cMinVal;
            if (cMaxVal != null)
                cMax[c] = cMaxVal;
        }
    }
    // for calibrated data, the offset from zero
    final double zeroOffset = getZeroOffset(imp);
    // fill in default display ranges as appropriate
    final double min, max;
    if (FormatTools.isFloatingPoint(pixelType)) {
        // no defined min and max values for floating point data
        min = max = Double.NaN;
    } else {
        final int bitDepth = reader.getBitsPerPixel();
        final double halfPow = Math.pow(2, bitDepth - 1);
        final double fullPow = 2 * halfPow;
        final boolean signed = FormatTools.isSigned(pixelType);
        if (signed) {
            // signed data is centered at 0
            min = -halfPow;
            max = halfPow - 1;
        } else {
            // unsigned data begins at 0
            min = 0;
            max = fullPow - 1;
        }
        for (int c = 0; c < cSize; c++) {
            if (Double.isNaN(cMin[c]))
                cMin[c] = min;
            if (Double.isNaN(cMax[c]))
                cMax[c] = max;
        }
    }
    // apply display ranges
    if (imp instanceof CompositeImage) {
        // apply channel display ranges
        final CompositeImage compImage = (CompositeImage) imp;
        for (int c = 0; c < cSize; c++) {
            LUT lut = compImage.getChannelLut(c + 1);
            // NB: Uncalibrate values before assigning to LUT min/max.
            lut.min = cMin[c] - zeroOffset;
            lut.max = cMax[c] - zeroOffset;
        }
    } else {
        // compute global display range from channel display ranges
        double globalMin = Double.POSITIVE_INFINITY;
        double globalMax = Double.NEGATIVE_INFINITY;
        for (int c = 0; c < cSize; c++) {
            if (cMin[c] < globalMin)
                globalMin = cMin[c];
            if (cMax[c] > globalMax)
                globalMax = cMax[c];
        }
        // NB: Uncalibrate values before assigning to display range min/max.
        globalMin -= zeroOffset;
        globalMax -= zeroOffset;
        // apply global display range
        ImageProcessor proc = imp.getProcessor();
        if (proc instanceof ColorProcessor) {
            // NB: Should never occur. ;-)
            final ColorProcessor colorProc = (ColorProcessor) proc;
            colorProc.setMinAndMax(globalMin, globalMax, 3);
        } else {
            ColorModel model = proc.getColorModel();
            proc.setMinAndMax(globalMin, globalMax);
            proc.setColorModel(model);
            imp.setDisplayRange(globalMin, globalMax);
        }
    }
}
Also used : VirtualImagePlus(loci.plugins.util.VirtualImagePlus) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) LUT(ij.process.LUT) IOException(java.io.IOException) FormatException(loci.formats.FormatException) ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) CompositeImage(ij.CompositeImage) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) MinMaxCalculator(loci.formats.MinMaxCalculator)

Example 2 with MinMaxCalculator

use of loci.formats.MinMaxCalculator in project bioformats by openmicroscopy.

the class ImportProcess method initializeStack.

/**
 * Performed following ImportStep.STACK notification.
 */
private void initializeStack() throws FormatException, IOException {
    IFormatReader r = baseReader;
    if (options.isGroupFiles()) {
        r = fileStitcher = new FileStitcher(baseReader);
        // overwrite base filename with file pattern
        String id = options.getId();
        fileStitcher.setId(id);
        fileStitcher.setUsingPatternIds(true);
        fileStitcher.setCanChangePattern(false);
    }
    r.setId(options.getId());
    if (options.isGroupFiles()) {
        options.setId(fileStitcher.getFilePattern().getPattern());
    }
    final byte[][] lut8 = r.get8BitLookupTable();
    final int sizeC = r.getSizeC();
    r = channelFiller = new ChannelFiller(r);
    if (channelFiller.isFilled()) {
        BF.warn(options.isQuiet(), getIdName() + ": index values will be lost");
    }
    r = channelSeparator = new ChannelSeparator(r);
    r = dimensionSwapper = new DimensionSwapper(r);
    if (options.isAutoscale() || FormatTools.isFloatingPoint(r)) {
        r = minMaxCalculator = new MinMaxCalculator(r);
    }
    if (options.doStitchTiles()) {
        r = tileStitcher = new TileStitcher(r);
    }
    r = virtualReader = new VirtualReader(r);
    reader = new ImageProcessorReader(r);
    if (options != null && !options.showROIs()) {
        baseReader.getMetadataOptions().setMetadataLevel(MetadataLevel.NO_OVERLAYS);
    }
    setId();
    computeSeriesLabels(reader);
}
Also used : IFormatReader(loci.formats.IFormatReader) FileStitcher(loci.formats.FileStitcher) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) MinMaxCalculator(loci.formats.MinMaxCalculator) DimensionSwapper(loci.formats.DimensionSwapper) TileStitcher(loci.formats.TileStitcher) ChannelFiller(loci.formats.ChannelFiller) VirtualReader(loci.plugins.util.VirtualReader) ChannelSeparator(loci.formats.ChannelSeparator)

Example 3 with MinMaxCalculator

use of loci.formats.MinMaxCalculator in project bioformats by openmicroscopy.

the class MinMaxCalculatorTest method setUp.

@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;
}
Also used : MinMaxCalculator(loci.formats.MinMaxCalculator) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MinMaxCalculator

use of loci.formats.MinMaxCalculator in project bioformats by openmicroscopy.

the class SPWModelReaderTest method testSetId.

@Test
public void testSetId() throws Exception {
    reader = new MinMaxCalculator(new ChannelSeparator(new ChannelFiller(new ImageReader())));
    metadata = new OMEXMLMetadataImpl();
    reader.setMetadataStore(metadata);
    reader.setId(temporaryFile.getAbsolutePath());
}
Also used : MinMaxCalculator(loci.formats.MinMaxCalculator) ChannelFiller(loci.formats.ChannelFiller) ImageReader(loci.formats.ImageReader) ChannelSeparator(loci.formats.ChannelSeparator) OMEXMLMetadataImpl(loci.formats.ome.OMEXMLMetadataImpl) Test(org.testng.annotations.Test)

Example 5 with MinMaxCalculator

use of loci.formats.MinMaxCalculator in project bioformats by openmicroscopy.

the class SPWModelReaderTest method testSetIdWithNoLightSources.

@Test
public void testSetIdWithNoLightSources() throws Exception {
    readerWithNoLightSources = new MinMaxCalculator(new ChannelSeparator(new ChannelFiller(new ImageReader())));
    metadataWithNoLightSources = new OMEXMLMetadataImpl();
    readerWithNoLightSources.setMetadataStore(metadataWithNoLightSources);
    readerWithNoLightSources.setId(temporaryFileWithNoLightSources.getAbsolutePath());
}
Also used : MinMaxCalculator(loci.formats.MinMaxCalculator) ChannelFiller(loci.formats.ChannelFiller) ImageReader(loci.formats.ImageReader) ChannelSeparator(loci.formats.ChannelSeparator) OMEXMLMetadataImpl(loci.formats.ome.OMEXMLMetadataImpl) Test(org.testng.annotations.Test)

Aggregations

MinMaxCalculator (loci.formats.MinMaxCalculator)13 ChannelFiller (loci.formats.ChannelFiller)11 ChannelSeparator (loci.formats.ChannelSeparator)11 ImageReader (loci.formats.ImageReader)10 FormatException (loci.formats.FormatException)6 ChannelMerger (loci.formats.ChannelMerger)5 DimensionSwapper (loci.formats.DimensionSwapper)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)4 FileStitcher (loci.formats.FileStitcher)4 IFormatReader (loci.formats.IFormatReader)4 OMEXMLMetadataImpl (loci.formats.ome.OMEXMLMetadataImpl)4 DataProvider (org.testng.annotations.DataProvider)3 Location (loci.common.Location)2 DependencyException (loci.common.services.DependencyException)2 ServiceException (loci.common.services.ServiceException)2 ServiceFactory (loci.common.services.ServiceFactory)2 Memoizer (loci.formats.Memoizer)2 MissingLibraryException (loci.formats.MissingLibraryException)2 OMEXMLService (loci.formats.services.OMEXMLService)2