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

Matplotlib Image Figures #7

Open
tibuch opened this issue Mar 14, 2022 · 7 comments
Open

Matplotlib Image Figures #7

tibuch opened this issue Mar 14, 2022 · 7 comments

Comments

@tibuch
Copy link

tibuch commented Mar 14, 2022

Hi Robert,

Super cool collection of notebooks!

One of my tasks is to teach users about bio-image analysis and I am in awe of the beauty of this collection. Thanks a lot for putting it together and making it publicly available. Instead of building my own collection I will totally use this and try to contribute where I can.

By coincidence one of the first things I did was a notebook and figure_utils.py that explains/helps users to plot their image data at a given print/display resolution: https://github.com/fmi-faim/py_course/blob/main/01-figures-in-python/Figures.ipynb

The target audience would be users that want save results at a requested resolution with a scalebar for publications or posters.

I could find some plotting notebooks, but not one tackling this specific area. If you agree I would like to submit this work as a PR to the repo.

Currently the figure_utils.py is a standalone collection of utility functions not published via pip. Would you recommend to put it on pip?

Best,
Tim-Oliver

PS: The license can be changed, currently it is MIT.

@haesleinhuepf
Copy link
Owner

Hey Tim-Oliver @tibuch ,

that sounds awesome! Of course, your notebook is very welcome as PR, e.g. in that folder:
https://github.com/haesleinhuepf/BioImageAnalysisNotebooks/tree/main/docs/60_data_visualization

Currently the figure_utils.py is a standalone collection of utility functions not published via pip. Would you recommend to put it on pip?

It looks well engineered and may of course be of interest to a broad audience. So yes, it would make sense to make it available on pypi. A potential alternative might be to send it as PR to @guiwitz' microfilm which has a similar purpose (and similar functionality) and is available on pypi already. Guillaume, what do you think?

Best,
Robert

@guiwitz
Copy link
Contributor

guiwitz commented Mar 17, 2022

It looks indeed like there's a lot of overlap with microfilm. The primary reason for making microfilm was the possibility of making multi-channel images à la Fiji, and I think that's missing from figure_utils.py (but I didn't look in detail). I'm just wondering @tibuch: you didn't know about microfilm (I didn't advertise much) or there was something specific you disliked about it? I'm genuinely curious because I made some design choices (API similar to matplotlib's imshow) that not everyone might like, so I'm happy about any feedback!

The nice thing in figure_utils.py is the use of the matplotlib_scalebar package. I learned about its exsitence only after having added my own scalebars. The possibility of making insets is also pretty cool. @tibuch I'll let you see if you want to develop something in parallel or if you'd like to contribute to microfilm!

Also a general question for @haesleinhuepf: in many notebooks you use skimage.io.imshow. I kind of remember that there's a plan to more or less drop the io module from skimage (and also I think most people don't use that imshow in general). Do you have a plan to replace it with Matplotlib? Or do you directly want to use something more dedicated to microscopy like figure_utils.py or microfilm?

Cheers,
Guillaume

@haesleinhuepf
Copy link
Owner

haesleinhuepf commented Mar 17, 2022

imshow [...] Do you have a plan to replace it with Matplotlib?

I'm more and more using pyclesperanto's imshow because it supports showing 3D data and we mostly work in 3D.

Its dependency towards OpenCL is a bit an issue. Anyway, matplotlibs imshow feels very clunky to me, especially when it comes to showing label images, blending them over raw data, using colorbars etc. See: https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/15_gpu_acceleration/clesperanto.html#processing-images

Note sure if proposing 3D/microscopy specific imshow functionality as PR to matplotlib or skimage is a way to go. Would it make sense to use microfilm instead @guiwitz ?

@guiwitz
Copy link
Contributor

guiwitz commented Mar 18, 2022

imshow [...] Do you have a plan to replace it with Matplotlib?

I'm more and more using pyclesperanto's imshow because it supports showing 3D data and we mostly work in 3D.

By "showing 3D data" do you mean that you can pass a 3D array and the plotting function does a projection automatically for you, as done here: https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/16_3d_image_visualization/10_nd_image_data.html#three-dimensional-image-stacks ? This is a great feature to allow people to quickly look at their images!

Its dependency towards OpenCL is a bit an issue. Anyway, matplotlibs imshow feels very clunky to me, especially when it comes to showing label images, blending them over raw data, using colorbars etc. See: https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/15_gpu_acceleration/clesperanto.html#processing-images

I agree with both points. Depending on OpenCL for potentially simply looking at images is too heavy. And regarding your second point, this is why I made microfilm: to avoid all the clunkiness of raw Matplotlib.

Note sure if proposing 3D/microscopy specific imshow functionality as PR to matplotlib or skimage is a way to go. Would it make sense to use microfilm instead @guiwitz ?

My impression is that Matplotlib want's to remain generalist and they sort of encourage the "building on top" approach that's used in pyclesperanto, microfilm or figure_utils.py. Regarding skimage, my impression from issue discussions is that they rather want to focus on algorithms and leave other areas like import, plotting etc. to other libraries (but I never contributed, so you may know better about this).

Summary: I think it makes sense to have a "specialized" approach and I'm open to any reasonable solution. If you like microfilm I'm happy to add features to match some of pyclesperanto's. Currently I'm thinking of:

  • the easy plotting of labels like imshow(image, labels=True)
  • the default projection plotting for 3D data. To avoid confusion with a multi-channel image it could be another function or also an option like imshow(image, project=True)

I think I will anyway add these features to microfilm as I like them. I'll leave it up to you to decide which solution you use in the end. I'm happy about any issue on microfilm to discuss API points (making a new function or adding options etc.)

@tibuch
Copy link
Author

tibuch commented Mar 21, 2022

It looks indeed like there's a lot of overlap with microfilm. The primary reason for making microfilm was the possibility of making multi-channel images à la Fiji, and I think that's missing from figure_utils.py (but I didn't look in detail). I'm just wondering @tibuch: you didn't know about microfilm (I didn't advertise much) or there was something specific you disliked about it? I'm genuinely curious because I made some design choices (API similar to matplotlib's imshow) that not everyone might like, so I'm happy about any feedback!

The nice thing in figure_utils.py is the use of the matplotlib_scalebar package. I learned about its exsitence only after having added my own scalebars. The possibility of making insets is also pretty cool. @tibuch I'll let you see if you want to develop something in parallel or if you'd like to contribute to microfilm!

Also a general question for @haesleinhuepf: in many notebooks you use skimage.io.imshow. I kind of remember that there's a plan to more or less drop the io module from skimage (and also I think most people don't use that imshow in general). Do you have a plan to replace it with Matplotlib? Or do you directly want to use something more dedicated to microscopy like figure_utils.py or microfilm?

Cheers, Guillaume

Hi @haesleinhuepf and @guiwitz,

Thanks Robert for connecting us :)

I did not know about microfilm! Looks very cool and I am happy to contribute to microfilm instead and then it might be interesting to get a microfilm example into this collection of BioImage Analysis Notebooks.

I also made a function to merge single channel images into one: https://github.com/fmi-faim/py_course/blob/main/01-figures-in-python/figure_utils.py#L292.

The main reason why I started this was to create figures where the images are scaled to have sufficient print-resolution: https://github.com/fmi-faim/py_course/blob/main/01-figures-in-python/figure_utils.py#L160

I have only glanced over microfilm so far, if you (@guiwitz) think that it makes sense to contribute the figures_util.py to microfilm I would dig a bit deeper and see how to integrate it best. Maybe we could meet quickly and see which functions are duplicates and which would be useful. If everything is already available via microfilm that is fine as well. Then I would probably try to recreate my example notebook with microfilm, but this is most likely also already covered. In that case I am just happy to have learned about microfilm ;)

Cheers,
Tim-Oliver

@guiwitz
Copy link
Contributor

guiwitz commented Mar 28, 2022

Hi @tibuch,

I think mostly microfilm should cover your needs. Regarding the output resolution, one can use the dpi=300 option. I'm not sure I want to have a specific function that outputs a fixed resolution image beyond this option. Do you have a specific need for such a function that you have in your module ?

The main thing that I didn't implement is the inset which in the frame of microscopy can be really useful. If you want to try to integrate this into microfilm I'm happy to help. But I can also try to add the feature myself if you don't have time!

Just to guide you: currently the image is implemented as a class called Microimage. The actual plotting is done by the function microshow which returns such a Microimage (the logic behind this was to allow users to create images without first having to create an object). That class implements all the "modification" methods such as adding a scalebar, a label etc. So when directly using the microshow function to create a plot, the following happens: a Microimage object is created, that object is then modified (via its methods) according to the options passed to microshow and finally the image is displayed.

So for the inset case, one would have to:

Let me know what you think!
Cheers
Guillaume

@tibuch
Copy link
Author

tibuch commented Apr 6, 2022

Hi @guiwitz,

The idea behind that function is to plot raw data at 300dpi. With the use-case that someone acquired an image with 2048x2048 pixels and wants to make a sharp figure. Then the figure should not be larger than 2048/300 * 2.54cm = 17cm squared on the poster. If it should be larger than that, one should use nearest neighbor interpolation to visualize pixels.
This calculation is independent of the figure (print) dpi, but crucial to have sharp images from raw data. Of course if the print dpi is then lower than 300 it will still be blurry.

I will try to add the insets to microfilm, but it will probably take a couple weeks :shipit:

Cheers,
Tim-Oliver

PS: I like the design choice that no object has to be created by the user!

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

3 participants