为什么gdal.open(path).ReadAsArray()从tiffile.imread(路径)产生不同的结果

发布于 2025-02-10 16:31:03 字数 627 浏览 1 评论 0原文

由于Colab不允许我通过给出错误的valueerror:< compression.lzw:5>需要“ ImageCodecs'软件包”,我使用gdal.open()。readAsarray()读取TIF文件并生成用于推断模型的输入数据。这将导致:

“在此处输入图像描述”

当我使用tiffile.imread()在另一个平台中读取相同的tif.file时,并使用与上述相同的过程创建了输入。模型预测最终转到:

”在此处输入图像描述”

第二张图像的结果对于我要预测的类是有意义的。我只想造成这种差异的原因。 GDAL似乎更改了像素的顺序?

Since colab won't allow me to use tiffile.imread() by giving error 'ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package', I use gdal.open().ReadAsArray() to read tif file and generate input data for model to inference. This results in:

enter image description here

When I use tiffile.imread() to read the same tif.file in another platform and created input with the same procedures as above. The model prediction finally goes to:

enter image description here

The results from the second image makes sense for the classes I want to predict. I just want to the reason that caused this difference. It seems gdal changed the order of pixels?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2025-02-17 16:31:03

这终于对我有用。由于我无法在Colab中使用Tiffile.imread(),因此我尝试了GDAL和RASTERIO,但是图像形状将首先是通道。第一个数字的问题是由于

np.reshape() 

没有更改数据维度轴的原因。
然后,我使用了下面的代码,并解决了问题。

with rio.open("gdrive/My Drive/file.tif") as ds:
  arr=ds.read()
np.moveaxis(arr, 0, -1)

This finally works for me. Since I cannot use tiffile.imread() in colab, I tried gdal and rasterio, but the image shape would be channel first. The problem for the first figure is caused by

np.reshape() 

which did not change the axis of data dimension.
Then I used codes below and the issue is addressed.

with rio.open("gdrive/My Drive/file.tif") as ds:
  arr=ds.read()
np.moveaxis(arr, 0, -1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文