首页 > 解决方案 > 在 python 中使用来自 imshow() 的缩放图像

问题描述

我正在使用 python 3.5 上的 GUI,关键是我在画布上显示图像并希望使用 matplotlib 工具使用zoom to rectanglepan/zoom按钮放大图像,然后已缩放的区域将其存储在变量上做一些图像处理,我可以实现一个按钮来提取一个区域,ginput()但我会从原始图像中丢失。现在我想尝试使用 matplotlib 的工具。

我该怎么做?谢谢

编辑:这就是我编码它的方式:

#On _init_ function on class I declare the figure like this
def __init__(self):
    self.raiz = tk.Tk()
    self.raiz.title("SOFTWARE KI-67")
    self.raiz.geometry('1000x800')

    self.figura=plt.figure()

    self.canvas = FigureCanvasTkAgg(self.figura, self.cuadro_plot)
    self.canvas.get_tk_widget().pack(side=tk.TOP, expand=tk.TRUE, fill=tk.BOTH)
    self.canvas.draw()
    self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.cuadro_plot)
    self.canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)


#This is the cutting function
def recortar(self):
    if self.brecortar.config('relief')[-1] == 'sunken':
        self.brecortar["state"] = 'normal'
    else:
        self.brecortar.config(relief="sunken")
        self.brecortar["state"] = 'disabled'
        pts = np.asarray(plt.ginput(2, show_clicks=True))
        pts = np.sort(pts, axis=0)
        pts = (np.floor(pts))
        print(pts)

        minX = int(min(pts[0][0], pts[1][0]))
        maxX = int(max(pts[0][0], pts[1][0]))
        minY = int(min(pts[0][1], pts[1][1]))
        maxY = int(max(pts[0][1], pts[1][1]))

        print(minX, maxX, minY, maxY)
        img2 = self.img.copy()
        img2 = img2[minY:maxY, minX:maxX]

        self.img = img2
        self.plotear(img2)

        self.brecortar.config(relief="raised")
        self.brecortar["state"] = 'normal'

我读了欧内斯特的评论,但我怎么能实现

ax.callbacks.connect('xlim_changed', on_xlims_change)
ax.callbacks.connect('ylim_changed', on_ylims_change)

??

标签: python-3.xmatplotlibimage-processing

解决方案


推荐阅读