1

I have a 3D numpy array, representing a 3D tomographic image I = [i,j,k].

I started to learn kivy as I need to do a simple GUI consisting of a 2D image viewer for each slice of the 3D (s = [i,:,:]) image and a slicer to move across planes.

I usually perform all visualization via matplotlib and I tough that the easiest way will be to connect matplotlib to the kivy. How can I do it? I saw another question which ask a similar question, but only with the plot function, and the methodology does not seems to work for imshow. (How to get started/use matplotlib in kivy).

Any suggestions?

Thanks,

Greynes
  • 719
  • 2
  • 7
  • 15

1 Answers1

2

Please refer to the example for details.

Example

main.py

from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import matplotlib.pyplot as plt
import matplotlib.image as mpimg


img = mpimg.imread('ac013.JPG')
lum_img = img[:, :, 0]
plt.imshow(lum_img, cmap="nipy_spectral")
plt.colorbar()


class TestApp(App):
    title = "Kivy Garden Matplolib & imshow()"

    def build(self):
        box = BoxLayout()
        box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
        return box


if __name__ == "__main__":
    TestApp().run()

Output

Img01

ikolim
  • 15,721
  • 2
  • 19
  • 29
  • Your solution works as expected, thanks. In your opinion, if I want to do an "slicer" of a 3d image with options such as "change the window level" or do a manual ROI, is this a valid way to work? Or I should use another way of visualitzation? – Greynes Aug 17 '18 at 08:40