Posted by
Michael Schmid on
Nov 13, 2014; 2:09pm
URL: http://imagej.273.s1.nabble.com/creating-a-real-blank-image-tp5010383p5010407.html
Hi Benjamin,
looks like you could do it with convolution:
0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 1
But this won't be the fastest option in terms of execution time, it does a lot of unnecessary multiplications by zero.
To get it a bit faster, discard the left 4 colums of the matrix, and translate the result by 2 pixels. This will leave some edge pixels undefined, however.
For a faster code, write a PlugInFilter. Typically you would specify the CONVERT_TO_FLOAT, DOES_ALL, SNAPSHOT, SUPPORTS_MASKING, PARALLELIZE_STACKS and (for large images) PARALLELIZE_IMAGES flags.
You find a very simple PlugInFilter example at
http://rsb.info.nih.gov/ij/plugins/apply-formula/Apply_Formula.javaIn your case, in the run(ip) method, take the snapshot pixels of the ImageProcessor (a float array with all pixels) as input and write to the pixels array (also float) as output. And you have to care about near-edge pixels, because some of the input pixels won't be inside the image for them.
float[] pixels = (float[])ip.getPixels();
float[] snapshotPixels = (float[])ip.getSnapshotPixels();
int width = ip.getWidth();
Rectangle roi = ip.getRoi();
for (int y=roi.y; y<roi.y + roi.height; y++) {
for (int x=roi.x; x<roi.x + roi.width; x++) {
// p points to pixel (x,y) in the arrays
// read input values as snapshot[x_input + y_input*width]
// calculate whatever you want
pixels[x + y*width] = result_of_calculation;
}
}
Michael
________________________________________________________________
On Nov 13, 2014, at 14:17, Benjamin Eltzner wrote:
> Dear list,
>
> I would like to write a plugin that does an operation at each pixel and
> takes into account only certain other pixels in the neighborhood of the
> pixel.
>
> Assume for example, I want to take the mean brightness of the pixel
> itself and 5 neighbors in a straight diagonal to its upper left and 5
> neighbors in a straight diagonal to its lower right. (So a rectangular
> mask for the convolve() method will not do.)
>
> Could you point me to the ImageJ API functions to accomplish this as
> efficiently (as in calculation time, not developer time) as possible? If
> you know a plugin that does something similar I would also be glad for a
> pointer.
>
>
> Best Regards,
>
> Benjamin
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html