use of ij.process.ByteProcessor in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method drawLoop.
private void drawLoop(ImagePlus imp, Roi roi, int number) {
if (!roi.isArea()) {
return;
}
// Map the ROI to a crop of the results set
final Rectangle roiBounds = roi.getBounds();
final Rectangle resultsBounds = results.getBounds(true);
// @formatter:off
final Rectangle2D.Double r = new Rectangle2D.Double(resultsBounds.width * (double) roiBounds.x / imp.getWidth(), resultsBounds.height * (double) roiBounds.y / imp.getHeight(), // Since we output pixels map the width/height to the nearest pixel
Math.ceil(resultsBounds.width * (double) roiBounds.width / imp.getWidth()), Math.ceil(resultsBounds.height * (double) roiBounds.height / imp.getHeight()));
// @formatter:on
final double x = r.getX();
final double y = r.getY();
final int magnification = getMagnification();
// For each result set crop out the localisation and construct an overlay
final Overlay o = new Overlay();
for (int i = 0; i < output.length; i++) {
final Color color = Settings.colors[i];
// The first result is the memory results
final MemoryPeakResults localResults = (MemoryPeakResults) output[i].getOutput(0);
localResults.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
if (r.contains(xx, yy)) {
add(o, (xx - x) * magnification, (yy - y) * magnification, color);
}
});
}
// This results in a change of shape depending on where the roi is positioned
int width = (int) r.getWidth();
int height = (int) r.getHeight();
width *= magnification;
height *= magnification;
final ImageProcessor ip = new ByteProcessor(width, height);
final String loopTitle = imp.getTitle() + " Loop " + number;
imp = WindowManager.getImage(loopTitle);
if (imp == null) {
imp = new ImagePlus(loopTitle, ip);
imp.show();
} else {
imp.setProcessor(ip);
imp.getWindow().toFront();
}
imp.setOverlay(o);
}
use of ij.process.ByteProcessor in project GDSC-SMLM by aherbert.
the class ImageConverterTest method createData.
private static Object createData(RandomSeed seed) {
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final ByteProcessor bp = new ByteProcessor(w, h);
final ImageConverterTestData data = new ImageConverterTestData();
data.bdata = (byte[]) bp.getPixels();
data.sdata = new short[data.bdata.length];
data.fdata = new float[data.bdata.length];
for (int i = 0; i < bp.getPixelCount(); i++) {
final int value = r.nextInt(256);
bp.set(i, value);
data.fdata[i] = data.sdata[i] = (short) value;
}
return data;
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class KMeansClusteringQuantizerApache method main.
// ----------------------------------------------------------------------
public static void main(String[] args) {
// String path = "D:/svn-book/Book/img/ch-color-images/alps-01s.png";
// String path = "D:/svn-book/Book/img/ch-color-images/desaturation-hsv/balls.jpg";
String path = "C:/_SVN/svn-book/Book/img/ch-color-images/desaturation-hsv/balls.jpg";
// String path = "D:/svn-book/Book/img/ch-color-images/single-color.png";
// String path = "D:/svn-book/Book/img/ch-color-images/two-colors.png";
// String path = "D:/svn-book/Book/img/ch-color-images/random-colors.png";
// String path = "D:/svn-book/Book/img/ch-color-images/ramp-fire.png";
int K = 16;
System.out.println("image = " + path);
System.out.println("K = " + K);
ImagePlus im = IJ.openImage(path);
if (im == null) {
System.out.println("could not open: " + path);
return;
}
ImageProcessor ip = im.getProcessor();
ColorProcessor cp = ip.convertToColorProcessor();
Parameters params = new Parameters();
params.maxColors = K;
ColorQuantizer quantizer = new KMeansClusteringQuantizerApache(cp, params);
quantizer.listColorMap();
System.out.println("quantizing image");
ByteProcessor qi = quantizer.quantize(cp);
System.out.println("showing image");
(new ImagePlus("quantizez", qi)).show();
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class CannyEdgeDetector method detectAndTraceEdges.
private void detectAndTraceEdges() {
if (Enms == null) {
nonMaxSuppression();
}
Ebin = new ByteProcessor(M, N);
int color = 255;
edgeTraces = new ArrayList<>();
for (int v = 0; v < N; v++) {
for (int u = 0; u < M; u++) {
if (Enms.getf(u, v) >= params.hiThr && Ebin.get(u, v) == 0) {
// unmarked edge point
EdgeTrace trace = traceAndThreshold(u, v, (float) params.loThr, color);
edgeTraces.add(trace);
}
}
}
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class ColorQuantizer method quantize.
// ---------------------------------------------------------------
/**
* Performs color quantization on the given full-color RGB image
* and creates an indexed color image.
*
* @param cp The original full-color RGB image.
* @return The quantized (indexed color) image.
*/
public default ByteProcessor quantize(ColorProcessor cp) {
float[][] colormap = this.getColorMap();
if (colormap.length > 256)
throw new RuntimeException("cannot index to more than 256 colors");
int w = cp.getWidth();
int h = cp.getHeight();
int[] rgbPixels = (int[]) cp.getPixels();
byte[] idxPixels = new byte[rgbPixels.length];
for (int i = 0; i < rgbPixels.length; i++) {
idxPixels[i] = (byte) findColorIndex(rgbPixels[i], colormap);
}
IndexColorModel idxCm = makeIndexColorModel(colormap);
return new ByteProcessor(w, h, idxPixels, idxCm);
}
Aggregations