use of ij.process.ShortProcessor in project TrakEM2 by trakem2.
the class ImageArrayConverter method ImageToFloatArray2DDeprecated.
public static float[][] ImageToFloatArray2DDeprecated(ImageProcessor ip) {
float[][] image;
Object pixelArray = ip.getPixels();
int count = 0;
if (ip instanceof ByteProcessor) {
image = new float[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 float[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 float[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] = pixels[count++];
} else // RGB
{
image = new float[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 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;
}
use of ij.process.ShortProcessor in project GDSC-SMLM by aherbert.
the class SplitResults method splitResults.
private void splitResults(MemoryPeakResults results, ImageProcessor ip) {
IJ.showStatus("Splitting " + TextUtils.pleural(results.size(), "result"));
// Create an object mask
final ObjectAnalyzer objectAnalyzer = new ObjectAnalyzer(ip, false);
final int maxx = ip.getWidth();
final int maxy = ip.getHeight();
final Rectangle bounds = results.getBounds();
final double ox = bounds.getX();
final double oy = bounds.getY();
final double scaleX = bounds.getWidth() / maxx;
final double scaleY = bounds.getHeight() / maxy;
// Create a results set for each object
final int maxObject = objectAnalyzer.getMaxObject();
final MemoryPeakResults[] resultsSet = new MemoryPeakResults[maxObject + 1];
for (int object = 0; object <= maxObject; object++) {
final MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
newResults.setName(results.getName() + " " + object);
resultsSet[object] = newResults;
}
final int[] mask = objectAnalyzer.getObjectMask();
if (settings.showObjectMask) {
final ImageProcessor objectIp = (maxObject <= 255) ? new ByteProcessor(maxx, maxy) : new ShortProcessor(maxx, maxy);
for (int i = 0; i < mask.length; i++) {
objectIp.set(i, mask[i]);
}
final ImagePlus imp = ImageJUtils.display(settings.objectMask + " Objects", objectIp);
imp.setDisplayRange(0, maxObject);
imp.updateAndDraw();
}
// Process the results mapping them to their objects
final Counter i = new Counter();
final int size = results.size();
final int step = ImageJUtils.getProgressInterval(size);
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
if (i.incrementAndGet() % step == 0) {
IJ.showProgress(i.getCount(), size);
}
// Map to the mask objects
final int object;
final int x = (int) ((xx - ox) / scaleX);
final int y = (int) ((yy - oy) / scaleY);
if (x < 0 || x >= maxx || y < 0 || y >= maxy) {
object = 0;
} else {
final int index = y * maxx + x;
// is within the bounds of the image processor?
if (index < 0 || index >= mask.length) {
object = 0;
} else {
object = mask[index];
}
}
resultsSet[object].add(result);
});
IJ.showProgress(1);
// Add the new results sets to memory
i.reset();
for (int object = (settings.nonMaskDataset) ? 0 : 1; object <= maxObject; object++) {
if (resultsSet[object].isNotEmpty()) {
MemoryPeakResults.addResults(resultsSet[object]);
i.increment();
}
}
IJ.showStatus("Split " + TextUtils.pleural(results.size(), "result") + " into " + TextUtils.pleural(i.getCount(), "set"));
}
use of ij.process.ShortProcessor in project GDSC-SMLM by aherbert.
the class ImageJImagePeakResults method createNewProcessor.
private ImageProcessor createNewProcessor(int imageWidth, int imageHeight) {
// Equalised display requires a 16-bit image to allow fast processing of the histogram
if ((displayFlags & DISPLAY_EQUALIZED) != 0) {
pixels = new short[data.length];
return new ShortProcessor(imageWidth, imageHeight, (short[]) pixels, null);
}
pixels = new float[data.length];
// Zero is mapped to 0 in the LUT.
if ((displayFlags & DISPLAY_MAPPED) != 0) {
final MappedFloatProcessor fp = new MappedFloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
fp.setMapZero((displayFlags & DISPLAY_MAP_ZERO) != 0);
return fp;
}
// -Infinity is mapped to 0 in the LUT.
if ((displayFlags & DISPLAY_NEGATIVES) != 0) {
return new InfinityMappedFloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
}
return new FloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
}
Aggregations