Create a gist now

Instantly share code, notes, and snippets.

ImageJ: colorize an image and rotate it
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.plugin.PlugIn;
import ij3d.ImageJ3DViewer;
public class Colorized_Rotation implements PlugIn {
@Override
public void run(String arg) {
// convert to grayscale image with RGB type
ImagePlus imp = IJ.getImage();
IJ.run(imp, "8-bit", "");
IJ.run(imp, "RGB Color", "");
// colorize the stack
ImageStack stack = imp.getImageStack();
int size = stack.getSize();
IJ.showStatus("Colorizing");
for (int n=0; n<size; n++) {
IJ.showProgress(n, size);
double weight = (double) n / (size - 1);
int[] pix = (int[]) stack.getProcessor(n + 1).getPixels();
for (int p=0; p<pix.length; p++) {
int value = pix[p] & 0xff;
int r = (int) ((1 - weight) * value);
int g = 0;
int b = (int) (weight * value);
pix[p] = (r << 16) | (g << 8) | b;
}
}
IJ.showStatus("");
imp.updateAndDraw();
// visualize in 3D with rotation
IJ.run("3D Viewer", "");
ImageJ3DViewer.setCoordinateSystem("false");
ImageJ3DViewer.add(imp.getTitle(), "None", imp.getTitle(), "0", "true", "true", "true", "1", "0");
ImageJ3DViewer.startAnimate();
}
}
@dscho
dscho commented May 23, 2014

I believe you wanted to use imp.getName() twice in line 37... ;-)

@ctrueden
Owner

@dscho Thanks! I changed it to imp.getTitle() in the relevant places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment