Skip to content

Instantly share code, notes, and snippets.

@rinze
Created July 13, 2012 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinze/3104185 to your computer and use it in GitHub Desktop.
Save rinze/3104185 to your computer and use it in GitHub Desktop.
ImagePlusHyp class extending ImageJ's ImagePlus.
package jclustering;
import ij.ImagePlus;
/**
* This class extends {@link ImagePlus} in order to add a handy {@link #getTac}
* method that allows to easily grab time-activity curves.
*
* @author <a href="mailto:jmmateos@mce.hggm.es">José María Mateos</a>.
*
*/
public class ImagePlusHyp extends ImagePlus {
/*
* dim[0] -> width (x)
* dim[1] -> height (y)
* dim[2] -> nChannels (1-based)
* dim[3] -> nSlices (1-based)
* dim[4] -> nFrames (1-based)
*/
private int[] dim;
private int ch;
/**
* Creates a new ImagePlusHyp using a general ImagePlus.
* @param ip The ImagePlus used to construct this class.
*/
public ImagePlusHyp(ImagePlus ip) {
super("HyperStack", ip.getStack());
this.setProcessor(ip.getProcessor());
this.setImage(ip);
this.dim = ip.getDimensions();
}
/**
* Gets the time-activity curve (dixel, after "dynamic pixel") for the
* given coordinates.
* @param x The x coordinate of the desired dixel.
* @param y The y coordinate of the desired dixel.
* @param z The z coordinate of the desired dixel.
* @return A float array containing the values for the given voxel
* on each frame, or null if the coordinates are not valid.
*/
public float[] getTac(int x, int y, int z) {
// Dimension check
if (x >= dim[0] || x < 0 || y >= dim[1] || y < 0 ||
z > dim[3] || z < 1) {
return null;
}
// Alloc space for the result
float[] result = new float[dim[4]];
// Set the desired slice and iterate through the frames
this.setSlice(z);
for (int i = 1; i <= dim[4]; i++) {
this.setT(i);
result[i-1] = Float.intBitsToFloat(this.getPixel(x, y)[0]);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment