use of ij.process.ColorProcessor in project GDSC-SMLM by aherbert.
the class ImageConverter method getDoubleData.
/**
* Get the data from the image as a double array (include cropping to the ROI). Data is duplicated if the
* input already a double array.
* <p>
* Allows reuse of an existing buffer if provided. This will not be truncated if it is larger than the
* ImageProcessor ROI bounds. If smaller then a new buffer will be created.
*
* @param oPixels
* @param width
* @param height
* @param bounds
* @param buffer
* @return The double array data
*/
public static double[] getDoubleData(final Object oPixels, final int width, final int height, final Rectangle bounds, double[] buffer) {
if (oPixels == null)
return null;
if (oPixels instanceof float[]) {
float[] pixels = (float[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
double[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++];
}
return pixels2;
} else {
double[] pixels2 = allocate(buffer, pixels.length);
for (int i = 0; i < pixels.length; i++) pixels2[i] = pixels[i];
return pixels2;
}
} else if (oPixels instanceof short[]) {
short[] pixels = (short[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
double[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++] & 0xffff;
}
return pixels2;
} else {
double[] pixels2 = allocate(buffer, pixels.length);
for (int i = 0; i < pixels.length; i++) pixels2[i] = pixels[i] & 0xffff;
return pixels2;
}
} else if (oPixels instanceof byte[]) {
byte[] pixels = (byte[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
double[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++] & 0xff;
}
return pixels2;
} else {
double[] pixels2 = allocate(buffer, pixels.length);
for (int i = 0; i < pixels.length; i++) pixels2[i] = pixels[i] & 0xff;
return pixels2;
}
} else if (oPixels instanceof int[]) {
// The default processing
ImageProcessor ip = new ColorProcessor(width, height, (int[]) oPixels);
ip.setRoi(bounds);
FloatProcessor fp = ip.crop().toFloat(0, null);
return (double[]) fp.getPixels();
}
return null;
}
use of ij.process.ColorProcessor in project GDSC-SMLM by aherbert.
the class ImageConverter method getData.
/**
* Get the data from the image as a float array (include cropping to the ROI). Data is duplicated if the
* input already a float array.
* <p>
* Allows reuse of an existing buffer if provided. This will not be truncated if it is larger than the
* ImageProcessor ROI bounds. If smaller then a new buffer will be created.
*
* @param oPixels
* @param width
* @param height
* @param bounds
* @param buffer
* @return The float array data
*/
public static float[] getData(final Object oPixels, final int width, final int height, final Rectangle bounds, float[] buffer) {
if (oPixels == null)
return null;
if (oPixels instanceof float[]) {
float[] pixels = (float[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
float[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++];
}
return pixels2;
} else {
float[] pixels2 = allocate(buffer, pixels.length);
System.arraycopy(pixels, 0, pixels2, 0, pixels.length);
return pixels2;
}
} else if (oPixels instanceof short[]) {
short[] pixels = (short[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
float[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++] & 0xffff;
}
return pixels2;
} else {
float[] pixels2 = allocate(buffer, pixels.length);
for (int i = 0; i < pixels.length; i++) pixels2[i] = pixels[i] & 0xffff;
return pixels2;
}
} else if (oPixels instanceof byte[]) {
byte[] pixels = (byte[]) oPixels;
if (bounds != null && (bounds.x != 0 || bounds.y != 0 || bounds.width != width || bounds.height != height)) {
float[] pixels2 = allocate(buffer, bounds.width * bounds.height);
for (int ys = bounds.y; ys < bounds.y + bounds.height; ys++) {
int offset1 = (ys - bounds.y) * bounds.width;
int offset2 = ys * width + bounds.x;
for (int xs = 0; xs < bounds.width; xs++) pixels2[offset1++] = pixels[offset2++] & 0xff;
}
return pixels2;
} else {
float[] pixels2 = allocate(buffer, pixels.length);
for (int i = 0; i < pixels.length; i++) pixels2[i] = pixels[i] & 0xff;
return pixels2;
}
} else if (oPixels instanceof int[]) {
// The default processing
ImageProcessor ip = new ColorProcessor(width, height, (int[]) oPixels);
ip.setRoi(bounds);
FloatProcessor fp = ip.crop().toFloat(0, null);
return (float[]) fp.getPixels();
}
return null;
}
Aggregations