python-3.x - 在 python 中使用来自 imshow() 的缩放图像
问题描述
我正在使用 python 3.5 上的 GUI,关键是我在画布上显示图像并希望使用 matplotlib 工具使用zoom to rectangle
或pan/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)
??
解决方案
推荐阅读
- reactjs - 在 ReactJs 中单击时添加新选项
- python - 松弛机器人 | 获取日期选择器值
- laravel - Laravel - Collection::delete 方法不存在
- powershell - 输出以从列表中选择 PS Gui 中的用户
- c# - 矢量化没有提供预期的加速
- angular - Angular 4+ 单元测试错误。由于语法错误,我无法进行单元测试
- python - Beautifulsoup 只抢了桌子的第一项
- css - 在 3 行网格内创建粘性页脚
- java - Graphics.fillRect 行为不一致 - 在某些机器上使用负高度和宽度进行绘制,但在其他机器上没有
- flutter - 调试横幅隐藏的一半!为什么?