use of javax.media.jai.KernelJAI in project vcell by virtualcell.
the class FRAPData method createCircularBinaryKernel.
private KernelJAI createCircularBinaryKernel(int radius) {
int enclosingBoxSideLength = radius * 2 + 1;
float[] kernalData = new float[enclosingBoxSideLength * enclosingBoxSideLength];
Point2D kernalPoint = new Point2D.Float(0f, 0f);
int index = 0;
for (int y = -radius; y <= radius; y++) {
for (int x = -radius; x <= radius; x++) {
if (kernalPoint.distance(x, y) <= radius) {
kernalData[index] = 1.0f;
}
index++;
}
}
return new KernelJAI(enclosingBoxSideLength, enclosingBoxSideLength, radius, radius, kernalData);
}
use of javax.media.jai.KernelJAI in project vcell by virtualcell.
the class UShortImage method createCircularBinaryKernel.
public static KernelJAI createCircularBinaryKernel(int radius) {
int enclosingBoxSideLength = radius * 2 + 1;
float[] kernalData = new float[enclosingBoxSideLength * enclosingBoxSideLength];
Point2D kernalPoint = new Point2D.Float(0f, 0f);
int index = 0;
for (int y = -radius; y <= radius; y++) {
for (int x = -radius; x <= radius; x++) {
if (kernalPoint.distance(x, y) <= radius) {
kernalData[index] = 1.0f;
}
index++;
}
}
return new KernelJAI(enclosingBoxSideLength, enclosingBoxSideLength, radius, radius, kernalData);
}
use of javax.media.jai.KernelJAI in project vcell by virtualcell.
the class UShortImage method fastDilate.
public static UShortImage fastDilate(UShortImage dilateSource, int radius, UShortImage mask) throws ImageException {
short[] sourcePixels = dilateSource.getPixels();
short[] targetPixels = dilateSource.getPixels().clone();
KernelJAI dilateKernel = createCircularBinaryKernel(radius);
float[] kernelData = dilateKernel.getKernelData();
BitSet kernelBitSet = new BitSet(kernelData.length);
for (int i = 0; i < kernelData.length; i++) {
if (kernelData[i] == 1.0f) {
kernelBitSet.set(i);
}
}
boolean bNeedsFill = false;
for (int y = 0; y < dilateSource.getNumY(); y++) {
int yOffset = y * dilateSource.getNumX();
int yMinus = yOffset - dilateSource.getNumX();
int yPlus = yOffset + dilateSource.getNumX();
for (int x = 0; x < dilateSource.getNumX(); x++) {
bNeedsFill = false;
if (sourcePixels[x + yOffset] != 0) {
if (x - 1 >= 0 && sourcePixels[(x - 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y - 1 >= 0 && sourcePixels[x + yMinus] == 0) {
bNeedsFill = true;
} else if (x + 1 < dilateSource.getNumX() && sourcePixels[(x + 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y + 1 < dilateSource.getNumY() && sourcePixels[x + yPlus] == 0) {
bNeedsFill = true;
}
if (bNeedsFill) {
int masterKernelIndex = 0;
for (int y2 = y - radius; y2 <= y + radius; y2++) {
if (y2 >= 0 && y2 < dilateSource.getNumY()) {
int kernelIndex = masterKernelIndex;
int targetYIndex = y2 * dilateSource.getNumX();
for (int x2 = x - radius; x2 <= x + radius; x2++) {
if (kernelBitSet.get(kernelIndex) && x2 >= 0 && x2 < dilateSource.getNumX()) {
targetPixels[targetYIndex + x2] = 1;
}
kernelIndex++;
}
}
masterKernelIndex += dilateKernel.getWidth();
}
}
}
}
}
UShortImage resultImage = new UShortImage(targetPixels, dilateSource.getOrigin(), dilateSource.getExtent(), dilateSource.getNumX(), dilateSource.getNumY(), dilateSource.getNumZ());
resultImage.and(mask);
return resultImage;
}
use of javax.media.jai.KernelJAI in project vcell by virtualcell.
the class FRAPData method fastDilate.
private UShortImage fastDilate(UShortImage dilateSource, int radius, UShortImage mask) throws ImageException {
short[] sourcePixels = dilateSource.getPixels();
short[] targetPixels = dilateSource.getPixels().clone();
KernelJAI dilateKernel = createCircularBinaryKernel(radius);
float[] kernelData = dilateKernel.getKernelData();
BitSet kernelBitSet = new BitSet(kernelData.length);
for (int i = 0; i < kernelData.length; i++) {
if (kernelData[i] == 1.0f) {
kernelBitSet.set(i);
}
}
boolean bNeedsFill = false;
for (int y = 0; y < dilateSource.getNumY(); y++) {
int yOffset = y * dilateSource.getNumX();
int yMinus = yOffset - dilateSource.getNumX();
int yPlus = yOffset + dilateSource.getNumX();
for (int x = 0; x < dilateSource.getNumX(); x++) {
bNeedsFill = false;
if (sourcePixels[x + yOffset] != 0) {
if (x - 1 >= 0 && sourcePixels[(x - 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y - 1 >= 0 && sourcePixels[x + yMinus] == 0) {
bNeedsFill = true;
} else if (x + 1 < dilateSource.getNumX() && sourcePixels[(x + 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y + 1 < dilateSource.getNumY() && sourcePixels[x + yPlus] == 0) {
bNeedsFill = true;
}
if (bNeedsFill) {
int masterKernelIndex = 0;
for (int y2 = y - radius; y2 <= y + radius; y2++) {
if (y2 >= 0 && y2 < dilateSource.getNumY()) {
int kernelIndex = masterKernelIndex;
int targetYIndex = y2 * dilateSource.getNumX();
for (int x2 = x - radius; x2 <= x + radius; x2++) {
if (kernelBitSet.get(kernelIndex) && x2 >= 0 && x2 < dilateSource.getNumX()) {
targetPixels[targetYIndex + x2] = 1;
}
kernelIndex++;
}
}
masterKernelIndex += dilateKernel.getWidth();
}
}
}
}
}
UShortImage resultImage = new UShortImage(targetPixels, dilateSource.getOrigin(), dilateSource.getExtent(), dilateSource.getNumX(), dilateSource.getNumY(), dilateSource.getNumZ());
resultImage.and(mask);
return resultImage;
}
Aggregations