use of ij.process.FloatProcessor in project TrakEM2 by trakem2.
the class Utils method fastConvertToFloat.
/**
* A method that circumvents the findMinAndMax when creating a float processor from an existing processor. Ignores color calibrations and does no scaling at all.
*/
public static final FloatProcessor fastConvertToFloat(final ShortProcessor ip) {
final short[] pix = (short[]) ip.getPixels();
final float[] data = new float[pix.length];
for (int i = 0; i < pix.length; i++) data[i] = pix[i] & 0xffff;
final FloatProcessor fp = new FloatProcessorT2(ip.getWidth(), ip.getHeight(), data, ip.getColorModel(), ip.getMin(), ip.getMax());
return fp;
}
use of ij.process.FloatProcessor in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToDoubleArray1DZeroPadding.
public static double[] ImageToDoubleArray1DZeroPadding(ImageProcessor ip, int width, int height) {
double[] image;
Object pixelArray = ip.getPixels();
int count = 0;
int offsetX = (width - ip.getWidth()) / 2;
int offsetY = (height - ip.getHeight()) / 2;
if (offsetX < 0) {
System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToDoubleArray1DZeroPadding(): Zero-Padding size in X smaller than image! " + width + " < " + ip.getWidth());
return null;
}
if (offsetY < 0) {
System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToDoubleArray1DZeroPadding(): Zero-Padding size in Y smaller than image! " + height + " < " + ip.getHeight());
return null;
}
if (ip instanceof ByteProcessor) {
image = new double[width * height];
byte[] pixels = (byte[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++] & 0xff;
} else if (ip instanceof ShortProcessor) {
image = new double[width * height];
short[] pixels = (short[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++] & 0xffff;
} else if (ip instanceof FloatProcessor) {
image = new double[width * height];
float[] pixels = (float[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++];
} else // RGB
{
image = new double[width * height];
int[] pixels = (int[]) pixelArray;
// still unknown how to do...
/*
for (int y = 0; y < ip.getHeight(); y++)
for (int x = 0; x < ip.getWidth(); x++)
image[x][y] = pixels[count++];// & 0xffffff;
*/
}
return image;
}
use of ij.process.FloatProcessor in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToIntArray.
public static int[][] ImageToIntArray(ImageProcessor ip) {
int[][] image;
Object pixelArray = ip.getPixels();
int count = 0;
if (ip instanceof ByteProcessor) {
image = new int[ip.getWidth()][ip.getHeight()];
byte[] pixels = (byte[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = pixels[count++] & 0xff;
} else if (ip instanceof ShortProcessor) {
image = new int[ip.getWidth()][ip.getHeight()];
short[] pixels = (short[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = pixels[count++] & 0xffff;
} else if (ip instanceof FloatProcessor) {
image = new int[ip.getWidth()][ip.getHeight()];
float[] pixels = (float[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = (int) pixels[count++];
} else // RGB
{
image = new int[ip.getWidth()][ip.getHeight()];
int[] pixels = (int[]) pixelArray;
// still unknown how to do...
/*
for (int y = 0; y < ip.getHeight(); y++)
for (int x = 0; x < ip.getWidth(); x++)
image[x][y] = pixels[count++];// & 0xffffff;
*/
}
return image;
}
use of ij.process.FloatProcessor in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToFloatArray2DZeroPadding.
public static FloatArray2D ImageToFloatArray2DZeroPadding(ImageProcessor ip, int width, int height) {
FloatArray2D image = new FloatArray2D(width, height);
Object pixelArray = ip.getPixels();
int count = 0;
int offsetX = (width - ip.getWidth()) / 2;
int offsetY = (height - ip.getHeight()) / 2;
if (offsetX < 0) {
System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToFloatArray2DZeroPadding(): Zero-Padding size in X smaller than image! " + width + " < " + ip.getWidth());
return null;
}
if (offsetY < 0) {
System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToFloatArray2DZeroPadding(): Zero-Padding size in Y smaller than image! " + height + " < " + ip.getHeight());
return null;
}
if (ip instanceof ByteProcessor) {
byte[] pixels = (byte[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++] & 0xff, x + offsetX, y + offsetY);
} else if (ip instanceof ShortProcessor) {
short[] pixels = (short[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++] & 0xffff, x + offsetX, y + offsetY);
} else if (ip instanceof FloatProcessor) {
float[] pixels = (float[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++], x + offsetX, y + offsetY);
} else // RGB
{
int[] pixels = (int[]) pixelArray;
// still unknown how to do...
/*
for (int y = 0; y < ip.getHeight(); y++)
for (int x = 0; x < ip.getWidth(); x++)
image[x][y] = pixels[count++];// & 0xffffff;
*/
}
return image;
}
use of ij.process.FloatProcessor in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToDoubleArray1D.
public static double[] ImageToDoubleArray1D(ImageProcessor ip) {
double[] image;
Object pixelArray = ip.getPixels();
int count = 0;
if (ip instanceof ByteProcessor) {
image = new double[ip.getWidth() * ip.getHeight()];
byte[] pixels = (byte[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++] & 0xff;
} else if (ip instanceof ShortProcessor) {
image = new double[ip.getWidth() * ip.getHeight()];
short[] pixels = (short[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++] & 0xffff;
} else if (ip instanceof FloatProcessor) {
image = new double[ip.getWidth() * ip.getHeight()];
float[] pixels = (float[]) pixelArray;
for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++];
} else // RGB
{
image = new double[ip.getWidth() * ip.getHeight()];
int[] pixels = (int[]) pixelArray;
// still unknown how to do...
/*
for (int y = 0; y < ip.getHeight(); y++)
for (int x = 0; x < ip.getWidth(); x++)
image[x][y] = pixels[count++];// & 0xffffff;
*/
}
return image;
}
Aggregations