Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"<BaSiC> There are no images open" during ImageJ --headless #1

Open
Anders-Lunde opened this issue Dec 1, 2020 · 14 comments
Open

"<BaSiC> There are no images open" during ImageJ --headless #1

Anders-Lunde opened this issue Dec 1, 2020 · 14 comments

Comments

@Anders-Lunde
Copy link

Hi. I'm trying to call basic during ImageJ headless execution, but I get the error message in the title.

ImagePlus stack = FolderOpener.open(currentChannelPath);
stack.setTitle("Stack.tif");
IJ.run(stack, "BaSiC ", "processing_stack=Stack.tif flat-field=None dark-field=None shading_estimation=[Estimate shading profiles] shading_model=[Estimate flat-field only (ignore dark-field)] setting_regularisationparametes=Automatic temporal_drift=Ignore correction_options=[Compute shading and correct images] lambda_flat=0.50 lambda_dark=0.50");

Then I get the error, even though the stack is opened. I run ImageJ from the command line using --headless and call the script above during excecution. Would greatly appreciate any help!

@loicsauteur
Copy link

Hi,
I run into the same trouble.
Currently, there is no workaround. The plugin will not run it in headless. One of the issues is that it requires a open image window...
The developers are working a new version, which will also address this issue.
Bests

@Anders-Lunde
Copy link
Author

I ended up using the Matlab implementation on Octave. This worked on a headless linux server, but made everything more complicated.

@tying84
Copy link
Collaborator

tying84 commented Feb 25, 2021

Actually Loic has a modified fiji version that allows you to run it headless. Maybe he could share with you.

@kaizen89
Copy link

@loicsauteur would you mind sharing this modified version? Thank you

@loicsauteur
Copy link

Hi @kaizen89
Sure. Please be aware that I did not fully test the modified plugin. But it worked with the example code I will provide.
My main motivation for modifying it, was to retrieve the corrected image.

For the installation:
Install BaSiC the conventional way. This makes sure you'll have all the dependencies...
Then replace the BaSiC_.jar in your plugin folder with the provided one.

code example (groovy):

import ij.IJ
import ij.ImagePlus
import ij.plugin.Duplicator


imp = IJ.openImage("http://imagej.nih.gov/ij/images/confocal-series.zip")
// duplicate only one channel
ori = new Duplicator().run(imp, 1, 1, 1, 25, 1, 1)
// FYI, the image must be a z-stack, no time-axis
imp.close()

//ori.show()

// start basic (v3)
bas = new BaSiC_()
bas.stack = ori.getStack()
bas.noOfSlices = ori.getNSlices()
println("before exec")

bas.exec(ori, null, null, "Estimate shading profiles", "Estimate both flat-field and dark-field", "Manual", 2.0, 2.0, "Replace with zero", "Compute shading and correct images")
println("after exec")

ImagePlus resultImp = bas.getCorrected_imp()
resultImp.setTitle("thatisthenewimage")

// Next, e.g. save the image to disc...

modifiedBaSiC_jar&java.zip

hope this helps!
cheers

@BioinfoTongLI
Copy link

Hi @loicsauteur, it's great that you are moving toward headless mode!
I've tried this modified version but got some kind of GUI required processing steps in the end of several iterations.

  Stop Criterion26  4.152174794658153E-4
  Stop Criterion27  2.646711539787849E-4
  Stop Criterion28  1.59724873942642E-4
  Stop Criterion29  9.294612938205516E-5
  Stop Criterion30  5.3083598012737176E-5
  Stop Criterion31  2.9920660070259428E-5
  Stop Criterion32  1.66370319424975E-5
  Stop Criterion33  9.23922513743425E-6
  Stop Criterion34  5.119917726900588E-6
  Stop Criterion35  2.865794154975991E-6
  Stop Criterion36  1.5977143030423399E-6
  Stop Criterion37  9.007451595687968E-7
  There are no images open

Just FYI, everything works fine with GUI. This happens only with Fiji headless mode
Do you think there's still some steps that needs selectWindow-like operation?

Best,
Tong

@loicsauteur
Copy link

Hi @BioinfoTongLI

Looks like it. But I don't see anything obvious anymore... (BTW: In the cases I experienced it was caused by IJ.run commands).

Not sure, if I can help.
You mind sharing the script you run in headless?

bests,

@BioinfoTongLI
Copy link

hi @loicsauteur,
Sure here is it.

shading = bas.exec(imp, null, null, "Estimate shading profiles", "Estimate both flat-field and dark-field", "Automatic", 0, 0, "Ignore", "Compute shading only")
println("after exec")

I just change it to "estimate shading only" as I want to save the flat-field image first and then apply to other images later.
And the after exec never got print out. So it should be internal in the exec command.
Potentially it is related to the option "compute shading only" option?

@loicsauteur
Copy link

Hi @BioinfoTongLI
I'm sorry, it is not super easy for me as this is not my code and a bit complicated for me. I just tried to modified it so it gets me what I wanted.
Why you get this error without the print of "after exec", I am not sure... I would check if the input is correct. Did you set

bas.stack = imp.getStack()
bas.noOfSlices = imp.getNSlices()

before calling the exec() function?
is your imp a single channel z-stack, and opened as such?
did you try running your script in the GUI or just clicked your way through the plugin?

As you probably figured out you need to specify the output of the exec() function to a new object, to retrieve the flatfield and darkfield. Something like:

bas = new BaSiC_()
bas.stack = imp.getStack()
bas.noOfSlices = imp.getNSlices()
println("before exec")

shading = bas.exec(imp, null, null, "Estimate shading profiles", "Estimate both flat-field and dark-field", "Automatic", 0, 0, "Ignore", "Compute shading only")
println("after exec")
flatfield = shading.getFlatfield()
darkfield = shading.getDarkfield()

This works in my case.

@BioinfoTongLI
Copy link

BioinfoTongLI commented May 19, 2021

@loicsauteur no problem at all! Thank you so much for all the information that you've provided! They are very much appreciated.

Yes, I did all the points that you've mentioned above. - hmm...Interesting. There might be something wrong with my data then.

Actually the ideal solution would be a Python implementation. Do you have any plans on that? @tying84 as raised in the other issue (#2 (comment))

@loicsauteur
Copy link

@BioinfoTongLI just for you to test. When I run following groovy script in GUI it shows the flat/dark-fields, while in headless it stops after printing "after exec". (With the BaSiC parameters you provided).

import ij.IJ
import ij.ImagePlus
import ij.plugin.Duplicator


imp = IJ.openImage("http://imagej.nih.gov/ij/images/confocal-series.zip")
ori = new Duplicator().run(imp, 1, 1, 1, 25, 1, 1)
imp.close()


// basic
bas = new BaSiC_()
bas.stack = ori.getStack()
bas.noOfSlices = ori.getNSlices()
println("noOfSlices = " + bas.noOfSlices) // check if input is a stack
println("before exec")

shading = bas.exec(ori, null, null, "Estimate shading profiles", "Estimate both flat-field and dark-field", "Automatic", 0, 0, "Ignore", "Compute shading only")
flatfield = shading.getFlatfield()
darkfield = shading.getDarkfield()
println("after exec")
flatfield.show()
darkfield.show()

@tying84
Copy link
Collaborator

tying84 commented May 19, 2021

yes, we have a Python implementation with Cellprofiler plugin, please refer to https://github.com/peng-lab/PyBasicCellprofilerPlugin and contact @Mirkazemi for details.

@BioinfoTongLI
Copy link

yes, we have a Python implementation with Cellprofiler plugin, please refer to https://github.com/peng-lab/PyBasicCellprofilerPlugin and contact @Mirkazemi for details.

Thanks @tying84 for the fast reply! it seems that this repo is currently not public? I don't see the project under your organization account.

@lguerard
Copy link

lguerard commented Aug 10, 2022

Hi @tying84 ,
I just came across this issue now, wanting the same thing and also interested in having the Fiji log info as an argument in order to avoid flooding the log window.

@loicsauteur and I would be interested in working on that by forking the original code, would it be possible to have the code available here on Github instead of a zip containing the JAR ? This would make collaboration easier :). Or would you have the new version of the plugin somewhere ?

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants