use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.
the class SwapDialog method harvestResults.
@Override
protected boolean harvestResults(GenericDialog gd) {
ImageProcessorReader reader = process.getReader();
int seriesCount = process.getSeriesCount();
for (int s = 0; s < seriesCount; s++) {
if (!options.isSeriesOn(s))
continue;
reader.setSeries(s);
int z = Integer.parseInt(gd.getNextChoice());
int c = Integer.parseInt(gd.getNextChoice());
int t = Integer.parseInt(gd.getNextChoice());
int originalZ = reader.getSizeZ();
int originalC = reader.getSizeC();
int originalT = reader.getSizeT();
String originalOrder = reader.getDimensionOrder();
StringBuffer sb = new StringBuffer();
sb.append("XY");
for (int i = 2; i < originalOrder.length(); i++) {
int originalValue = 0;
switch(originalOrder.charAt(i)) {
case 'Z':
originalValue = originalZ;
break;
case 'C':
originalValue = originalC;
break;
case 'T':
originalValue = originalT;
break;
}
if (originalValue == z && sb.indexOf("Z") < 0) {
sb.append("Z");
} else if (originalValue == c && sb.indexOf("C") < 0) {
sb.append("C");
} else if (originalValue == t && sb.indexOf("T") < 0) {
sb.append("T");
}
}
options.setInputOrder(s, sb.toString());
}
return true;
}
use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.
the class Slicer method makeStack.
/**
* Returns a new ImageStack using the given ImageStack as a template.
*/
private ImageStack makeStack(ImageStack stack) {
if (!(stack instanceof BFVirtualStack)) {
return new ImageStack(stack.getWidth(), stack.getHeight());
}
BFVirtualStack virtualStack = (BFVirtualStack) stack;
String path = virtualStack.getPath();
ImageProcessorReader reader = virtualStack.getReader();
try {
return new BFVirtualStack(path, reader, false, false, false);
} catch (FormatException e) {
WindowTools.reportException(e);
} catch (IOException e) {
WindowTools.reportException(e);
}
return null;
}
use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.
the class Read_Image method run.
public void run(String arg) {
OpenDialog od = new OpenDialog("Open Image File...", arg);
String dir = od.getDirectory();
String name = od.getFileName();
String id = dir + name;
ImageProcessorReader r = new ImageProcessorReader(new ChannelSeparator(LociPrefs.makeImageReader()));
try {
IJ.showStatus("Examining file " + name);
r.setId(id);
int num = r.getImageCount();
int width = r.getSizeX();
int height = r.getSizeY();
ImageStack stack = new ImageStack(width, height);
byte[][][] lookupTable = new byte[r.getSizeC()][][];
for (int i = 0; i < num; i++) {
IJ.showStatus("Reading image plane #" + (i + 1) + "/" + num);
ImageProcessor ip = r.openProcessors(i)[0];
stack.addSlice("" + (i + 1), ip);
int channel = r.getZCTCoords(i)[1];
lookupTable[channel] = r.get8BitLookupTable();
}
IJ.showStatus("Constructing image");
ImagePlus imp = new ImagePlus(name, stack);
ImagePlus colorizedImage = applyLookupTables(r, imp, lookupTable);
r.close();
colorizedImage.show();
IJ.showStatus("");
} catch (FormatException exc) {
IJ.error("Sorry, an error occurred: " + exc.getMessage());
} catch (IOException exc) {
IJ.error("Sorry, an error occurred: " + exc.getMessage());
}
}
use of loci.plugins.util.ImageProcessorReader 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;
}
use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.
the class Colorizer method makeLUTs.
private LUT[] makeLUTs(int series) {
final ImageProcessorReader reader = process.getReader();
reader.setSeries(series);
LUT[] luts = new LUT[reader.getSizeC()];
for (int c = 0; c < luts.length; c++) luts[c] = makeLUT(series, c);
return luts;
}
Aggregations