use of ij.process.ShortProcessor 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.ShortProcessor 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.ShortProcessor 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.ShortProcessor 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;
}
use of ij.process.ShortProcessor in project GDSC-SMLM by aherbert.
the class CreateData method updateArea.
private void updateArea(int[] mask, int width, int height) {
// Note: The apparent area will be bigger due to the PSF width blurring the edges.
// Assume the entire max intensity mask is in focus and the PSF is Gaussian in the focal plane.
// Blur the mask
final float[] pixels = new float[mask.length];
for (int i = 0; i < pixels.length; i++) {
pixels[i] = mask[i];
}
final GaussianFilter blur = new GaussianFilter();
final double scaleX = (double) settings.getSize() / width;
final double scaleY = (double) settings.getSize() / height;
// Allow extra?
final double extra = 1;
final double sd = getPsfSd() * extra;
blur.convolve(pixels, width, height, sd / scaleX, sd / scaleY);
// Count pixels in blurred mask. Ignore those that are very faint (at the edge of the region)
int count = 0;
// // By fraction of max value
// float limit = 0.1f;
// //float min = (float) (Maths.max(pixels) * limit);
// float min = limit;
// for (float f : pixels)
// if (f > min)
// c++;
// // Rank in order and get fraction of sum
// Arrays.sort(pixels);
// double sum = 0;
// double stop = Maths.sum(pixels) * 0.95;
// float after = Maths.max(pixels) + 1;
// for (float f : pixels)
// {
// sum += f;
// if (sum > stop)
// {
// break;
// //after = f;
// //stop = Float.POSITIVE_INFINITY;
// }
// if (f > after)
// break;
// c++;
// }
// Threshold to a mask
final FloatProcessor fp = new FloatProcessor(width, height, pixels);
final ShortProcessor sp = (ShortProcessor) fp.convertToShort(true);
final int t = AutoThreshold.getThreshold(AutoThreshold.Method.OTSU, sp.getHistogram());
// Utils.display("Blurred", fp);
for (int i = 0; i < mask.length; i++) {
if (sp.get(i) >= t) {
count++;
}
}
// Convert
final double scale = ((double) count) / mask.length;
// System.out.printf("Scale = %f\n", scale);
areaInUm = scale * settings.getSize() * settings.getPixelPitch() * settings.getSize() * settings.getPixelPitch() / 1e6;
}
Aggregations