如何绘制图像的有限区域?

时间:2021-04-19 19:00:29

标签: python matplotlib

如果我有一个 [556,556] PX 形式的图像并且我想绘制它们的某个范围,那么说:

Image Size: [556,556]

Plot -> XPixels [224,300] YPixels [224,300]

这是我的尝试,它确实是我需要它做的事情,我选择了正确的像素,但不幸的是,这只标记了给定的范围,实际上并未绘制该范围。可以理解,接下来的部分将是绘制给定图像的新范围,但我将如何处理?

openDicom = pdi.dcmread(filePath)
plt.imshow(openDicom.pixel_array, cmap=plt.cm.Spectral, origin = 'lower',interpolation = 'nearest')
plt.xticks([308,341])
plt.yticks([234,271])

请参阅我的“惊人绘图”以获取更多参考。谢谢!

enter image description here

1 个答案:

答案 0 :(得分:1)

只需将数组子区域传递给 imshow。

plt.imshow(image[y_start:y_end, x_start:x_end])