简体   繁体   English

Matplotlib imshow 和 kivy

[英]Matplotlib imshow and kivy

I have a 3D numpy array, representing a 3D tomographic image I = [i,j,k].我有一个 3D numpy 数组,表示 3D 断层图像 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.我开始学习 kivy,因为我需要做一个简单的 GUI,其中包括一个 3D (s = [i,:,:]) 图像的每个切片的 2D 图像查看器和一个跨平面移动的切片器。

I usually perform all visualization via matplotlib and I tough that the easiest way will be to connect matplotlib to the kivy.我通常通过 matplotlib 执行所有可视化,我认为最简单的方法是将 matplotlib 连接到 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.我看到另一个问题,它提出了类似的问题,但仅使用 plot 函数,并且该方法似乎不适用于 imshow。 ( How to get started/use matplotlib in kivy ). 如何在 kivy 中开始/使用 matplotlib )。

Any suggestions?有什么建议?

Thanks,谢谢,

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输出

图像01

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM