-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add conversion support for index images to ImgLib2 and legacy ImageJ ROIs #283
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #283 +/- ##
==========================================
+ Coverage 77.68% 77.81% +0.13%
==========================================
Files 16 16
Lines 1949 2010 +61
==========================================
+ Hits 1514 1564 +50
- Misses 435 446 +11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great tutorial @elevans!
Just had some small suggestions.
@elevans I created an environment with the indicated yml and When I paste the exact same line into a python interpreter launched in the exact same environment that started jupyter, it works no problem. :( I noticed that I'm using python 3.8 locally and I think you used 3.11 when you made the |
@hinerm I ran using the following name: cellstar
channels:
- conda-forge
- defaults
dependencies:
- python=="3.8"
- pyimagej
- jupyterlab
- openjdk=11
- pip
- pip:
- tensorflow==2.12.*
- stardist
- cellpose and things seem to work fine. How did you install python 3.8? |
@gselzer it's just my system python, since it wasn't specified in the I'm trying with your method of specification. Interestingly I earlier tried Further interestingly, Edit: specifying |
@hinerm I updated the jupyter notebook to use |
Do I need to do anything different to install it? I assume if you use I assume the environment file should now be: name: cellstar
channels:
- conda-forge
- defaults
dependencies:
- python=3.8
- pyimagej
- jupyterlab
- openjdk=11
- pip Anyway, this doesn't work for me. It looks like the What version of |
This commit adds converts that convert index images (java or python) into ImgLib2 rois (in a ROITree) or as ImageJ rois populated in the RoiManager.
If the current session is in headless mode catch the JException and do nothing.
I added a better description and more comments to the code. I also fixed a typo.
Instead of using NumPy arrays to generate boolean masks for each label (an expensive operation), we can use an ImgLabeling and query the regions instead. This method is 5.73 times faster than the my previous NumPy implementation.
After troubleshooting on Linux, Windows and macOS I found using a combination of mamba and pip commands worked best. I also made some minor changes for macOS. If macOs is detected, the notebook changes its mode from `interactive` to `headless`.
acbfae3
to
e3710d8
Compare
@hinerm After many hours of painful testing across Linux, Windows and macOS I found the following shell commands to be the most successful for installing %%capture
!mamba install -y -c conda-forge tensorflow stardist
!pip install cellpose I tested this on the following systems:
While testing on macOS, I got bit by the lack of |
When displaying the final image output the cytoplasmic channel is too dim to see. The user needs to adjust the brightness/contrast in ImageJ/Fiji.
I'm going to do something spicy 🌶️ and merge this branch. The actual new code in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @elevans—this is great work. I have a couple of requests, though:
- I'd like to avoid promising
DefaultWritablePolygon2D
, in favor of using the interface where needed. - Ideally, the conversion logic between index images and ImgLib2 ROIs would live in imagej-common, and simply get called from Python. Then people on the Java side can take advantage of it as well in their scripts.
I would be OK merging this branch once the issue with DefaultWritablePolygon2D
is addressed, since we can add the Java-side conversion logic afterward and then replace the code here with a more concise method call. But I would appreciate it if you could do it soon, before we forget about it.
Finally, about the brightness/contrast adjustment: did you try automating that? If so, did you run into any problems? I'm happy to help figure out how to do it, and/or fix any bugs relating to that, as needed.
Instead of using the default implementation, DefaultWritablePolygon2D, I should use the interface: WritablePolygon2D.
Apply the Brightness/Contrast standard "auto" adjust to the second channel (cytoplasmic channel) after displaying the data.
Awesome, thanks @elevans! |
This PR adds support to convert index images (Python or Java) into either of the following:
net.imagej.roi.DefaultROITree
populated with ImgLib2 ROIs.RoiManager
populated with legacy converted ROIs (e.g.net.imagej.legacy.convert.roi.polygon2d.Polygon2DWrapper
).Because there's no real way to tell the difference between an index image and some other type of image data (without making assumptions) I feel its best to not register these index image functions with
scyjava/pyimagej
converters.Included in this PR:
To run the use case you'll need Cellpose and StarDist. This
environment.yml
file should do the trick:Don't forget to pull this branch and
pip install -e .
before running the notebook!