Giter Club home page Giter Club logo

Comments (12)

tlambert03 avatar tlambert03 commented on July 28, 2024 7

There are a lot of moving parts there, and it is going to require a fair amount of doing. I will say that the general design of that pipeline (load image, click button for analysis, show results of analysis visually and in tabular format, and then link the visualization of the data with the tabular data) is one of the main eventual goals for napari. So you're in good company! But each step is going to require some work, and some of them (like linking the data visualization to the tabular data) will almost certainly require some changes within napari itself.

but here is some higher level guidance for the short term. And we intend to improve our docs around building GUI elements soon, so stay tuned:

  • to add a gui element, like a button, you may wish to create your own QWidget. to that widget, you would then need to add a QLayout... and then add a QPushButton to the layout with addWidget. Something like:

    from qtpy.QtWidgets import QWidget, QVBoxLayout, QPushButton
    
    mywidget = QWidget()
    layout = QVBoxLayout()
    mywidget.setLayout(layout)
    button = QPushButton()
    layout.addWidget(button)
  • once created, you can add that widget as a docked widget to the napari viewer with the Window.add_dock_widget method, like this:

    viewer.window.add_dock_widget(mywidget)
  • Qt offers many similar GUI elements (beyond push buttons)... so read up in their docs (and google) to find specific objects that you can also add to your layout.

  • to execute "something" on a button click (and general UI interactivity), you need to use Qt signals & slots. In this case you need to connect your callback function that actually executes the segmentation to the clicked signal on the button.

    def my_segmentation_routine(*args, **kwargs):
        # ... do segmentation
        # for now, you may wish to access data in, e.g. ... viewer.layers[0].data
    
    button.clicked.connect(my_segmentation_routine)
  • in your segmentation, you might create something like a Labels layer, that you can have added to the viewer.

  • then for interacting with individual objects, you'll need to implement some mouseover callbacks. @VolkerH had a good example of doing something like that with @labels_layer.mouse_move_callbacks here: napari/napari#531 (comment), and he made his code available here. @kne42 also made an example for using custom mouse event callbacks here.

  • if you actually want to view the tabular data in napari, we don't have any built-in tables at the moment, but just as before with the pushButton example, you could make a QTableWidget, and populate it with data retrieved from the mouse event.

Hope that gets you started. Ultimately, there are many steps in here that I'm sure we would like to provide "official" ways of doing... and we hope to also allow plugins to take care of some of these steps (and you might in turn create such a plugin that could be shared). But until then, I hope this helps to get you started.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024 2

I'll add here, for anyone looking to extend napari with basic GUIs, I started a package magicgui that attempts to automate a lot of this stuff. You write a function and add type annotations to your parameters, and magicgui will auto-generate a widget for you that you can add to napari with viewer.window.add_dock_widget(). It's still in early alpha, but feel free to play around with it. Here are some napari-focused tutorials: image arithmetic, parameter sweeps

As of napari/napari#981, napari comes with some built-in support for creating magicgui widgets from functions using napari Layer types as type annotations.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024 1

ahh yes... I need to fix that for PyQt5. I'll get to that shortly, but in the meantime you can either use pyside2 instead of pyqt5 (pip uninstall pyqt5 -y; pip install pyside2), or go into the magicgui folder in your site-packages and just remove all references to SignalInstance as long as you can get it to import, all functionality will be there). I'll try to get to that within a couple days.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024 1

just pushed an update to pypi. magicgui v0.1.2 should work for PyQt5.
though, as noted, it's in pre-alpha, so definitely let me know if you run into more bugs over in the magicgui issue tracker.

from napari.github.io.

jni avatar jni commented on July 28, 2024

Hi @jesusdpa1!

Currently I am working with images with size (25600, 49152, 3) px and I am trying to slice the image in smaller sizes to accelerate the computation.

It would be best for you to give us some example code here... It is critical that your chunk size and your computation size are well-aligned. How is the data currently stored? What type of analysis are you trying to do?

At any rate, the analysis question and the visualisation are very different questions. For analysis, it would be best to set up an example code snippet, with example data, and post a question tagged with "dask" on stack overflow.

For visualisation, ideally, you should store your data as a tiled pyramid. @sofroniewn has created a 2D pyramid in zarr format using this code:

https://github.com/sofroniewn/image-demos/blob/master/helpers/make_2D_zarr_pathology.py

But again, your code might look different depending on your source data.

After you have your data in that format, you can use napari.view_image(path='path/to/data.zarr', is_pyramid=True) to look at it. However, adding some dask caching is helpful here. See:

https://github.com/sofroniewn/image-demos/blob/master/examples/pathology.py

For an example.

Also, is it possible to use napari as the base for the image analysis tool that I am currently developing?

Yes!

In the long term, we are hoping to provide plugin infrastructure to make it easy for you to add your functionality by publishing a package on PyPI. In the short term, I'm going to ask @tlambert03 or @sofroniewn to provide some sample code for adding a Qt dockable widget with keybindings and callbacks, as I haven't kept up to date with the Qt code...

Also, I would recommend asking napari questions at image.sc with the napari tag, as that is more searchable/discoverable in the long term. Thanks!

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

Also, is it possible to use napari as the base for the image analysis tool that I am currently developing? I would like to include buttons and other user interface to facilitate the search and processing of the images.

Hi @jesusdpa1, happy to provide some guidance on the gui stuff here. Can you give me a little more information on what you'd like to achieve? i.e. what pressing the buttons will do, and what you mean by "other user interface".

from napari.github.io.

jesusdpa1 avatar jesusdpa1 commented on July 28, 2024

Hi Talley,

Thanks for your fast reply! So I would like to be able to load the image from napari, have click on buttons to execute the segmentation algorithm. and then include a panel to search individual objects inside of the image. In the last step I am interested in showing all the measurements for that object selected like an excel sheet.

from napari.github.io.

jesusdpa1 avatar jesusdpa1 commented on July 28, 2024

Wow! Thank you very much!

I'm going to start working on the modification. I'll keep you posted if any more question appear on the process, and let you know if I manage to create the plugins to share.

On another topic. I am plotting images with shapes (25600, 49152, 3) or larger on the x,y axis and I have notice that the viewer usually crops the right size of the image on the display. I can still access the data if a move the image to the left, but, is there a way to update the image window to display the entire image?

from napari.github.io.

jesusdpa1 avatar jesusdpa1 commented on July 28, 2024

Thanks Talley! This is really amazing,

I have try to install magicgui but when I try to load the module I get the following error

from qtpy.QtCore import Signal, SignalInstance, Qt
ImportError: cannot import name 'SignalInstance' from 'qtpy.QtCore'

from napari.github.io.

jesusdpa1 avatar jesusdpa1 commented on July 28, 2024

Thank you!

No more errors in that part. I got a new one when trying to run any example: it usually says:

get_layers() takes 1 positional argument but 2 were given

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

can you open an issue at that link I posted above and provide the full traceback?

from napari.github.io.

jesusdpa1 avatar jesusdpa1 commented on July 28, 2024

sure will do!

from napari.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.