RGBStackMerge out of range: 1

Hi all,

I’m trying to merge some ImagePlusthat I have in order to make a composite out of it using RGBStackMerge but I’m getting a weird error Argument out of range: 1

Here is my call :

imp_rgb = RGBStackMerge.mergeChannels([imp4,imp2,imp1],False)

I also saw this post but it doesn’t work for me, even the first time, is it linked ?

Thanks !

As mentioned in the topic you linked, this seems to be a problem with conversion/synchronization between ImageJ1 objects (ImagePlus) and ImageJ2 objects (Dataset, Img, etc., used explicitly in scripts or implicitly via script parameters…).

@lguerard can you post your full script please?

1 Like

HI @imagejan,

Thanks for your reply !

My full script is a patchwork established after multiple weeks/month so it’s not the prettiest nor the best one but it works :sweat_smile:

If only the lines showing the ImagePlus are enough, here they are :

from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.plugin import Duplicator, ImageCalculator, Concatenator, RGBStackMerge

#@ImagePlus imp

imp2 = imp.duplicate()

channel_of_interest = 1
all_imp1 = Duplicator().run(imp2, channel_of_interest, channel_of_interest, 1, imp2.getNSlices(), 1, 1)
imp_to_add = IJ.createImage("empty", "16-bit black", imp2.getWidth(), imp2.getHeight(), shift_slices_sox9)
imp1 = Concatenator.run(imp_to_add,all_imp1)

channel_of_interest = 3
all_imp3 = Duplicator().run(imp2, channel_of_interest, channel_of_interest, 1, imp2.getNSlices(), 1, 1)
imp_to_add = IJ.createImage("empty", "16-bit black", imp2.getWidth(), imp2.getHeight(), shift_slices_sox9)
imp3 = Concatenator.run(imp_to_add,all_imp3)

channel_of_interest = 4
all_imp4 = Duplicator().run(imp2, channel_of_interest, channel_of_interest, 1, imp2.getNSlices(), 1, 1)
imp_to_add = IJ.createImage("empty", "16-bit black", imp2.getWidth(), imp2.getHeight(), shift_slices_sox9)
imp4 = Concatenator.run(all_imp4,imp_to_add)

# Fails with out of range: 1
imp_rgb = RGBStackMerge.mergeChannels([imp4,imp3,imp1],False)

Edit : I guess there was actually a typo in my code since this is now working after multiple edits… Sorry about this.