Has anyone managed to use convertStackToImages()?

I have a CompositeImage. Although it’s actually an RGB image, but mistakenly interpreted as a stack of 3 images. In order to correct this, I can do Image> Stack > Stack to images or IJ.run("Stack to Images", "") and then IJ.run("Merge Channels...",str).

I looked for a way to avoid using IJ,run and ij.plugin.StackEditor.convertStackToImages(imp) appears to be just the right one for this purpose but it throws error when used with an ImagePlus object as an argument.

No method 'convertStackToImages' with matching signature found for class
'ij.plugin.StackEditor'. 

Has anyone managed to use convertStackToImages()? Is there any other way to achieve this? Or should I just stick to IJ.run()?

Also, what’s the alternative of IJ.run("Merge Channels...",str)?

Good day,

if you agree to stay for a moment with the GUI functions of ImageJ, would

“Image >> Color >> Channels Tool… >> More >> Convert to RGB”

do what you want?

If yes, you may record the operation with the macro recorder using Java as language.

Regards

Herbie

Thanks. In my hands, it didn’t work properly. The result was a stack of 3 RGB images that look like grayscale.

And I actually want to stay out of GUI functions and achieve the goal with Java API.

Perhaps you didn’t perfectly describe what your original data looks like because for me it works.

And I actually want to stay out of GUI functions and achieve the goal with Java API.

As I’ve written (“if you agree to stay for a moment with the GUI functions”), I’m aware of this but most often it helps if you know a way that works.

Have success

Herbie

Here is a composite test image in a zip-archive
clown_asChannelsRGB.tif.zip (148.9 KB)

and here is the plugin java code that does the conversion to RGB:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class _composite2rgb implements PlugIn {
	public void run(String arg) {
		ImagePlus imp = IJ.getImage();
		IJ.run(imp, "Stack to RGB", "");
	}
}

HTH

Herbie

Thanks. It looks like we can’t really get away from IJ,run().

Also when I tried another example from ImageJ’s sample image, your suggestion above (“Image >> Color >> Channels Tool… >> More >> Convert to RGB”) worked.

It looks like we can’t really get away from IJ,run().

I don’t agree but the question is: Is it necessary to get away…

If you look at the APIs and then go to “StackConverter” you find a method:
(http://mirror.imagej.net/developer/api/ij/process/StackConverter.html#convertToRGB–)

**convertToRGB**

public void convertToRGB()

Converts the Stack to RGB.

HTH

Herbie

Back to the original question, I have to admit my example with 3 channels wasn’t good. Because in the end, I want to do this for an image with more than three channels.

In this scenario, convertStackToImages seems to be the right one, and it didn’t work.

Thanks a lot for your input anyway. I’ll probably stick with IJ.run() which is working at the moment.