use of javax.media.jai.PlanarImage in project vcell by virtualcell.
the class FRAPData method erodeDilate.
private UShortImage erodeDilate(UShortImage source, KernelJAI dilateErodeKernel, UShortImage mask, boolean bErode) throws ImageException {
PlanarImage completedImage = null;
PlanarImage operatedImage = null;
PlanarImage planarSource = binarize(source);
Integer borderPad = dilateErodeKernel.getWidth() / 2;
planarSource = BorderDescriptor.create(planarSource, borderPad, borderPad, borderPad, borderPad, BorderExtender.createInstance(BorderExtender.BORDER_ZERO), null).createInstance();
if (bErode) {
planarSource = AddConstDescriptor.create(planarSource, new double[] { 1.0 }, null).createInstance();
RenderedOp erodeOP = ErodeDescriptor.create(planarSource, dilateErodeKernel, null);
operatedImage = erodeOP.createInstance();
} else {
RenderedOp dilationOP = DilateDescriptor.create(planarSource, dilateErodeKernel, null);
operatedImage = dilationOP.createInstance();
}
operatedImage = CropDescriptor.create(operatedImage, new Float(0), new Float(0), new Float(source.getNumX()), new Float(source.getNumY()), null);
operatedImage = binarize(operatedImage.getAsBufferedImage());
if (mask != null) {
RenderedOp andDescriptor = AndDescriptor.create(operatedImage, binarize(mask), null);
completedImage = andDescriptor.createInstance();
} else {
completedImage = operatedImage;
}
return convertToUShortImage(completedImage, source.getOrigin(), source.getExtent());
}
use of javax.media.jai.PlanarImage in project vcell by virtualcell.
the class FRAPData method binarize.
private PlanarImage binarize(BufferedImage source) {
PlanarImage planarSource = PlanarImage.wrapRenderedImage(source);
double[][] minmaxArr = (double[][]) ExtremaDescriptor.create(planarSource, null, 1, 1, false, 1, null).getProperty("extrema");
short[] lookupData = new short[0x010000];
lookupData[(int) minmaxArr[1][0]] = 1;
LookupTableJAI lookupTable = new LookupTableJAI(lookupData, true);
planarSource = LookupDescriptor.create(planarSource, lookupTable, null).createInstance();
return planarSource;
}
use of javax.media.jai.PlanarImage in project vcell by virtualcell.
the class VFrap_OverlayImageDisplayJAI method refreshImage.
public void refreshImage() {
if (underlyingImage != null && highlightImage != null) {
PlanarImage sourceOverlay = null;
alphaImageUnderlying = makeAlpha(underlyingImage, .6f);
alphaImageHightlight = makeAlpha(highlightImage, .3f);
RenderedImage contrastEnhancedUnderlyingImage = underlyingImage;
if (contrastFactor > 0) {
// Contrast stretch
double[][] minmaxArr = null;
if (minmaxPixelValues != null) {
minmaxArr = new double[][] { { minmaxPixelValues.getMin() }, { minmaxPixelValues.getMax() } };
} else {
minmaxArr = (double[][]) ExtremaDescriptor.create(underlyingImage, null, 1, 1, false, 1, null).getProperty("extrema");
}
if ((minmaxArr[1][0] - minmaxArr[0][0]) != 0) {
double offset = (SCALE_MAX * minmaxArr[0][0]) / (minmaxArr[0][0] - minmaxArr[1][0]);
double scale = (SCALE_MAX) / (minmaxArr[1][0] - minmaxArr[0][0]);
contrastEnhancedUnderlyingImage = RescaleDescriptor.create(underlyingImage, new double[] { scale }, new double[] { offset }, null);
}
// enhance with gamma function
if (contrastFactor > 1) {
byte[] tableData = new byte[256];
for (int i = 0; i < 256; i++) {
double normalizedWithGamma = Math.pow((i / 255.0), 1 / (1.0 + (contrastFactor - 1) / 5.0));
int val = (int) (normalizedWithGamma * 255);
if (val > 255) {
val = 255;
}
tableData[i] = (byte) (val & 0xFF);
}
LookupTableJAI table = new LookupTableJAI(tableData);
contrastEnhancedUnderlyingImage = LookupDescriptor.create(contrastEnhancedUnderlyingImage, table, null);
}
}
sourceOverlay = CompositeDescriptor.create(contrastEnhancedUnderlyingImage, highlightImage, alphaImageUnderlying, alphaImageHightlight, false, CompositeDescriptor.NO_DESTINATION_ALPHA, null);
sourceOverlay = ScaleDescriptor.create(sourceOverlay, zoom, zoom, 0f, 0f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), null);
set(sourceOverlay, 0, 0);
} else {
set(new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB), 0, 0);
}
}
use of javax.media.jai.PlanarImage in project vcell by virtualcell.
the class UShortImage method binarize.
private static PlanarImage binarize(BufferedImage source) {
PlanarImage planarSource = PlanarImage.wrapRenderedImage(source);
double[][] minmaxArr = (double[][]) ExtremaDescriptor.create(planarSource, null, 1, 1, false, 1, null).getProperty("extrema");
short[] lookupData = new short[0x010000];
lookupData[(int) minmaxArr[1][0]] = 1;
LookupTableJAI lookupTable = new LookupTableJAI(lookupData, true);
planarSource = LookupDescriptor.create(planarSource, lookupTable, null).createInstance();
return planarSource;
}
use of javax.media.jai.PlanarImage in project vcell by virtualcell.
the class UShortImage method erodeDilate.
public static UShortImage erodeDilate(UShortImage source, KernelJAI dilateErodeKernel, UShortImage mask, boolean bErode) throws ImageException {
PlanarImage completedImage = null;
PlanarImage operatedImage = null;
PlanarImage planarSource = binarize(source);
Integer borderPad = dilateErodeKernel.getWidth() / 2;
planarSource = BorderDescriptor.create(planarSource, borderPad, borderPad, borderPad, borderPad, BorderExtender.createInstance(BorderExtender.BORDER_ZERO), null).createInstance();
if (bErode) {
planarSource = AddConstDescriptor.create(planarSource, new double[] { 1.0 }, null).createInstance();
RenderedOp erodeOP = ErodeDescriptor.create(planarSource, dilateErodeKernel, null);
operatedImage = erodeOP.createInstance();
} else {
RenderedOp dilationOP = DilateDescriptor.create(planarSource, dilateErodeKernel, null);
operatedImage = dilationOP.createInstance();
}
operatedImage = CropDescriptor.create(operatedImage, new Float(0), new Float(0), new Float(source.getNumX()), new Float(source.getNumY()), null);
operatedImage = binarize(operatedImage.getAsBufferedImage());
if (mask != null) {
RenderedOp andDescriptor = AndDescriptor.create(operatedImage, binarize(mask), null);
completedImage = andDescriptor.createInstance();
} else {
completedImage = operatedImage;
}
return convertToUShortImage(completedImage, source.getOrigin(), source.getExtent());
}
Aggregations