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);
}
}
}
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);
}
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;
}
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());
}
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());
}
Aggregations