use of loci.formats.DimensionSwapper in project bioformats by openmicroscopy.
the class WrapperTest method createWrappers.
@DataProvider(name = "wrappers")
public Object[][] createWrappers() {
Location.mapId(TEST_FILE, TEST_FILE);
Object[][] wrappers = new Object[][] { { new ChannelFiller() }, { new ChannelMerger() }, { new ChannelSeparator() }, { new DimensionSwapper() }, { new FileStitcher() }, { new ImageReader() }, { new MinMaxCalculator() }, { new Memoizer() } };
for (int i = 0; i < wrappers.length; i++) {
IFormatReader reader = (IFormatReader) wrappers[i][0];
try {
reader.setId(TEST_FILE);
} catch (FormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return wrappers;
}
use of loci.formats.DimensionSwapper in project bioformats by openmicroscopy.
the class Colorizer method applyColors.
// -- Colorizer methods --
public List<ImagePlus> applyColors(List<ImagePlus> imps) {
final ImporterOptions options = process.getOptions();
final ImageProcessorReader reader = process.getReader();
final DimensionSwapper dimSwapper = process.getDimensionSwapper();
final ChannelFiller channelFiller = process.getChannelFiller();
final ImageReader imageReader = process.getImageReader();
for (int i = 0; i < imps.size(); i++) {
ImagePlus imp = imps.get(i);
final int series = (Integer) imp.getProperty(ImagePlusReader.PROP_SERIES);
reader.setSeries(series);
// get LUT for each channel
final String stackOrder = dimSwapper.getDimensionOrder();
final int zSize = imp.getNSlices();
final int cSize = imp.getNChannels();
final int tSize = imp.getNFrames();
final int stackSize = imp.getStackSize();
final LUT[] channelLUTs = new LUT[cSize];
boolean hasChannelLUT = false;
for (int c = 0; c < cSize; c++) {
final int index = FormatTools.getIndex(stackOrder, zSize, cSize, tSize, stackSize, 0, c, 0);
channelLUTs[c] = (LUT) imp.getProperty(ImagePlusReader.PROP_LUT + index);
if (channelLUTs[c] != null)
hasChannelLUT = true;
}
// compute color mode and LUTs to use
int mode = -1;
LUT[] luts;
if (options.isColorModeDefault()) {
// NB: Default color mode behavior depends on the situation.
final boolean isRGB = reader.isRGB() || imageReader.isRGB();
if (isRGB || channelFiller.isFilled()) {
// NB: The original data had more than one channel per plane
// (e.g., RGB image planes), so we use the composite display mode.
mode = CompositeImage.COMPOSITE;
// preserve original LUTs
luts = makeLUTs(channelLUTs, true);
} else if (hasChannelLUT) {
// NB: The original data had only one channel per plane,
// but had at least one lookup table defined. We use the color
// display mode, with missing LUTs as grayscale.
mode = CompositeImage.COLOR;
// preserve original LUTs
luts = makeLUTs(channelLUTs, true);
} else {
// NB: The original data had only one channel per plane,
// and had no lookup tables defined, so we use the grayscale mode.
mode = CompositeImage.GRAYSCALE;
luts = null;
}
} else if (options.isColorModeComposite()) {
mode = CompositeImage.COMPOSITE;
// preserve existing channel LUTs
luts = makeLUTs(channelLUTs, true);
} else if (options.isColorModeColorized()) {
mode = CompositeImage.COLOR;
// preserve existing channel LUTs
luts = makeLUTs(channelLUTs, true);
} else if (options.isColorModeGrayscale()) {
mode = CompositeImage.GRAYSCALE;
// use default (grayscale) channel LUTs
luts = null;
} else if (options.isColorModeCustom()) {
mode = CompositeImage.COLOR;
// override any existing channel LUTs
luts = makeLUTs(series);
} else {
throw new IllegalStateException("Invalid color mode: " + options.getColorMode());
}
// apply color mode and LUTs
final boolean doComposite = !options.isViewStandard() && mode != -1 && cSize > 1 && cSize <= 7;
if (doComposite) {
final ImagePlus toClose = imp;
CompositeImage compImage = new CompositeImage(imp, mode) {
@Override
public void close() {
super.close();
toClose.close();
}
@Override
public void show(String message) {
super.show(message);
// see ticket #12267
if (toClose instanceof VirtualImagePlus) {
int channel = getChannel();
double min = getDisplayRangeMin();
double max = getDisplayRangeMax();
for (int c = 0; c < cSize; c++) {
setPositionWithoutUpdate(c + 1, getSlice(), getFrame());
setDisplayRange(min, max);
}
reset();
setPosition(channel, getSlice(), getFrame());
}
}
};
compImage.setProperty(ImagePlusReader.PROP_SERIES, series);
if (luts != null)
compImage.setLuts(luts);
imps.set(i, compImage);
imp = compImage;
} else {
// NB: Cannot use CompositeImage for some reason.
if (luts != null && luts.length > 0 && luts[0] != null) {
if (imp instanceof VirtualImagePlus) {
((VirtualImagePlus) imp).setLUTs(luts);
} else if (cSize == 1)
imp.getProcessor().setColorModel(luts[0]);
}
if (mode != -1 && cSize > 7) {
// NB: Cannot use CompositeImage with more than seven channels.
BF.warn(options.isQuiet(), "Data has too many channels for " + options.getColorMode() + " color mode");
}
}
applyDisplayRanges(imp, series);
}
return imps;
}
Aggregations