Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created June 22, 2023 20:57
Show Gist options
  • Save bogovicj/ec8efdb1c6fbff9c63f523d0538f2a7d to your computer and use it in GitHub Desktop.
Save bogovicj/ec8efdb1c6fbff9c63f523d0538f2a7d to your computer and use it in GitHub Desktop.
ImageJ2 script to perform an operation over the rows of a dataset
#@ Dataset img
/**
* Perform an operation on every row of the input image.
*
* This sets every pixel in the first row to have value zero,
* the second row will have value one, etc.
*
* https://forum.image.sc/t/best-way-to-iterate-over-columns-rows/82472
*/
// number of rows = length in the y-dimension
nrows = img.dimension(1);
// value starts at zero
value = Util.getTypeFromInterval(img);
for( long r = 0; r < nrows; r++ ) {
// get the rth row of the image
rowImage = Views.hyperSlice( img, 1, r )
// set every pixel in the row to value
rowImage.forEach( x -> {
x.set(value);
});
// increment value (value = value + 1)
value.inc();
}
import net.imglib2.view.Views;
import net.imglib2.util.Util;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment