use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToFloatArray2D.
public static FloatArray2D ImageToFloatArray2D(ImageProcessor ip) {
FloatArray2D image;
Object pixelArray = ip.getPixels();
int count = 0;
if (ip instanceof ByteProcessor) {
image = new FloatArray2D(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.data[count] = pixels[count++] & 0xff;
} else if (ip instanceof ShortProcessor) {
image = new FloatArray2D(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.data[count] = pixels[count++] & 0xffff;
} else if (ip instanceof FloatProcessor) {
image = new FloatArray2D(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.data[count] = pixels[count++];
} else // RGB
{
image = new FloatArray2D(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