在 Matplotlib 中绘制相对于彼此的图像
Plotting images relative to each other in Matplotlib
我正在研究具有朝下摄像头的机器人。为了展示我的定位过滤器是如何工作的,我想用机器人的路径在图表中绘制草地。这意味着我必须将旋转的图像放置在图表中。是否可以通过旋转绘制相对于原点或彼此的图像?
我想避免使用 ndimage.rotate,因为它会旋转图像的数据,而不是轴中的图像。
我尝试使用:
import import matplotlib.pyplot as mplplt
import matplotlib.transforms as mpltf
import matplotlib.image as mplimg
grass = mplimg.imread("grass0.png")
grass = mplimg.imread("grass1.png")
fig = mplplt.figure()
ax = mplplt.subplot(111)
#Show previous grass image
ax.imshow(grass, extent = (-5, 5, -5, 5))
#Next image
tf = mpltf.Affine2D().rotate_deg(30).translate(1,1)
ax.imshow(grass1, extent = (-5, 5, -5, 5))#, transform = tf)
mplplt.show()
无济于事,该图像位于上一个图像之上。
这是一个示例,其中包含一张图像的两份副本,不同的旋转和平移,一个在下一个之上。大量的限制调整和 Z 排序以及制作易于理解的功能,所有这些都剩下要做。我科学怪人你的代码和 http://matplotlib.org/examples/api/demo_affine_image.html:
import matplotlib.pyplot as mplplt
import matplotlib.transforms as mpltf
import matplotlib.image as mplimg
def imshow_affine(ax, z, *kl, **kwargs):
im = ax.imshow(z, *kl, **kwargs)
x1, x2, y1, y2 = im.get_extent()
im._image_skew_coordinate = (x2, y1)
return im
grass = mplimg.imread("hammer_map.png")
fig = mplplt.figure()
ax = mplplt.subplot(111)
tf = mpltf.Affine2D().rotate_deg(30).translate(-1,-1) + ax.transData
im1 = imshow_affine(ax, grass, interpolation='none',
origin='lower',
extent=[1, 7, 0, 5], clip_on=False, zorder=2)
im1.set_transform(tf)
tf = mpltf.Affine2D().rotate_deg(190).translate(-2,1) + ax.transData
im2 = imshow_affine(ax, grass, interpolation='none',
origin='lower',
extent=[-3, 3, -2, 3], clip_on=False, zorder=1)
im2.set_transform(tf)
mplplt.show()
我正在研究具有朝下摄像头的机器人。为了展示我的定位过滤器是如何工作的,我想用机器人的路径在图表中绘制草地。这意味着我必须将旋转的图像放置在图表中。是否可以通过旋转绘制相对于原点或彼此的图像?
我想避免使用 ndimage.rotate,因为它会旋转图像的数据,而不是轴中的图像。
我尝试使用:
import import matplotlib.pyplot as mplplt
import matplotlib.transforms as mpltf
import matplotlib.image as mplimg
grass = mplimg.imread("grass0.png")
grass = mplimg.imread("grass1.png")
fig = mplplt.figure()
ax = mplplt.subplot(111)
#Show previous grass image
ax.imshow(grass, extent = (-5, 5, -5, 5))
#Next image
tf = mpltf.Affine2D().rotate_deg(30).translate(1,1)
ax.imshow(grass1, extent = (-5, 5, -5, 5))#, transform = tf)
mplplt.show()
无济于事,该图像位于上一个图像之上。
这是一个示例,其中包含一张图像的两份副本,不同的旋转和平移,一个在下一个之上。大量的限制调整和 Z 排序以及制作易于理解的功能,所有这些都剩下要做。我科学怪人你的代码和 http://matplotlib.org/examples/api/demo_affine_image.html:
import matplotlib.pyplot as mplplt
import matplotlib.transforms as mpltf
import matplotlib.image as mplimg
def imshow_affine(ax, z, *kl, **kwargs):
im = ax.imshow(z, *kl, **kwargs)
x1, x2, y1, y2 = im.get_extent()
im._image_skew_coordinate = (x2, y1)
return im
grass = mplimg.imread("hammer_map.png")
fig = mplplt.figure()
ax = mplplt.subplot(111)
tf = mpltf.Affine2D().rotate_deg(30).translate(-1,-1) + ax.transData
im1 = imshow_affine(ax, grass, interpolation='none',
origin='lower',
extent=[1, 7, 0, 5], clip_on=False, zorder=2)
im1.set_transform(tf)
tf = mpltf.Affine2D().rotate_deg(190).translate(-2,1) + ax.transData
im2 = imshow_affine(ax, grass, interpolation='none',
origin='lower',
extent=[-3, 3, -2, 3], clip_on=False, zorder=1)
im2.set_transform(tf)
mplplt.show()