Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 {
public void run(String arg) {
// convert to grayscale image with RGB type
ImagePlus imp = IJ.getImage();, "8-bit", "");, "RGB Color", "");
// colorize the stack
ImageStack stack = imp.getImageStack();
int size = stack.getSize();
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;
// visualize in 3D with rotation"3D Viewer", "");
ImageJ3DViewer.add(imp.getTitle(), "None", imp.getTitle(), "0", "true", "true", "true", "1", "0");

This comment has been minimized.

Copy link

@dscho dscho commented May 23, 2014

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


This comment has been minimized.

Copy link
Owner Author

@ctrueden ctrueden commented May 23, 2014

@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
You can’t perform that action at this time.