[英]python matplotlib.pyplot imread
I'm using plt.imread
for reading big .tiff images.我正在使用
plt.imread
读取大 .tiff 图像。 Because of the big dimensions, I would like to select just a part of the image to be loaded.由于尺寸较大,我只想选择要加载的图像的一部分。 I would like to do something like:
我想做类似的事情:
plt.imread(filename, [s1:s2, r1:r2])
choosing the initial and final pixel for both dimensions.为两个维度选择初始和最终像素。
Is there a way to do this?有没有办法做到这一点?
Many thanks非常感谢
I think you have to read the entire image, after which you can slice it before you do any processing on it:我认为您必须阅读整个图像,然后您可以在对其进行任何处理之前对其进行切片:
import matplotlib.pyplot as plt
my_img = plt.imread('my_img.tiff')
my_clipped_img = my_img[s1:s2,r1:r2]
or, in one line:或者,在一行中:
import matplotlib.pyplot as plt
my_img = plt.imread('my_img.tiff')[s1:s2,r1:r2]
The latter has the benefit of not creating a full sized array, but just of the size you want.后者的好处是不创建完整大小的数组,而只是创建您想要的大小。
Bear in mind that s1:s2 here should be your limits in the vertical direction, and r1:r2 in the horizontal direction.请记住,这里的 s1:s2 应该是垂直方向的极限,而 r1:r2 应该是水平方向的极限。
The only way that it would be possible to read only a portion of the file would be if it were in a columnar format and partitioned on disk both horizontally (rows) and vertically (columns).可以只读取文件一部分的唯一方法是,如果它采用列格式并在磁盘上水平(行)和垂直(列)分区。 Hive , and Hadoop provide such mechanisms (and Spark supports them).
Hive和Hadoop提供了这样的机制( Spark支持它们)。 But those are for more datastores and not for individual (image) files.
但这些是针对更多数据存储的,而不是针对单个(图像)文件的。
So the answer from tmdavison
is correct - and maybe this provides some better feel for why that is.所以
tmdavison
的答案是正确的——也许这让我们更好地了解为什么会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.