Last active
August 29, 2015 14:01
-
-
Save ctrueden/fe00e8dd2034f37273f0 to your computer and use it in GitHub Desktop.
ImageJ: colorize an image and rotate it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe you wanted to use
imp.getName()
twice in line 37... ;-)