Open images as a stack (works with a given path but not with an element of a list because of SyntaxError)

Dear Forum,

I wrote a macro in python to apply contrast enhancement with different percentages .
For this purpose I have made a GenericDialog Box with different checkboxes. If a checkbox is TRUE, the macro opens a stack with images and applies contrast enhancement. Hence, I save the path of each stack in a list called “Output”.
So far so good.

Now I want to use this code to open the images as a stack:

IJ.run("Image Sequence...", "open=["Output[0]"] sort")

But this does not work, because of a SyntaxError.
I tried a test with the whole path in the code and it works.

IJ.run("Image Sequence...", "open=[/Users/mate/Desktop/preparation/contastenhancement/stack1/.DS_Store] sort")

This code also doesn’t work because it can’t open the whole images as a stack. That’s why I prefer the code before.

imp = IJ.openImage(os.path.join(Output[0]))

What is the correct syntax?

I can’t believe I’m failing here.
Thank you for any advice!

Dear Forum,

I solved this problem. I removed .DS_Store and used FolderOpener.
Here is the result:

k = []
for i in Output:
  j = i.replace('.DS_Store','')
  k.append(j)
 
           
#Open all images as stack  
from ij.plugin import FolderOpener
options = "sort"
path = k[0]
imp = FolderOpener.open(path, options)
imp.show()
1 Like