如何降低10m分辨率的TIFF映像,并创建一个50m的新图像,每个像素是第一个图像的统计信息?
初始TIFF映像是二进制分类图 - 意味着每个像素(10m)属于“水”(值= 0)或类“ ICE”(值= 1)的类。
我想创建一个新图像,其中每个像素是初始地图的5 x 5块中水百分比,这意味着新图像的每个像素都将具有50 m的分辨率,并且表示“水的比率或百分比” “以前地图的每5x5像素上的像素。您可以在此处看到示例:示例
这是一个映像示例(可以从Google驱动器下载):
How to downscale a tiff image of 10m resolution and create a new image of 50m where each pixel is stats from the first image?
The initial tiff image is a binary classification map - meaning each pixel (10m) belongs either to class "water" (value =0) or class "ice" (value=1).
I would like to create a new image, where each pixel is the percentage of water in a 5 x 5 block of the initial map, meaning each pixel of the new image will have a 50 m resolution and represents the ratio or percentage of "water" pixel on every 5x5 pixel of the former map. You can see the example here: Example
Here is an image sample (can be downloaded from google drive):
https://drive.google.com/uc?export=download&id=19hWQODERRsvoESiUZuL0GQHg4Mz4RbXj
发布评论
评论(2)
您的图像以一种相当奇怪的格式保存,使用32位浮子仅表示可以用一点点表示的两类数据,因此我用 imagemagick 使用:
许多Python库会在您的实际TIFF上结结巴巴,因此也许要考虑使用另一种编写方式。
完成此操作后,代码可能看起来像这样:
在反射上,您可以更快地进行操作,而更简单地使用
Your image is saved in a rather odd format, using a 32-bit float to represent just two classes of data which could be represented in a single bit, so I converted it to PNG with ImageMagick using:
Many Python libraries will stutter on your actual TIFF so maybe think about using a different way of writing it.
Once that is done, the code might look something like this:
On reflection, you can probably do it faster and more simply with cv2.resize() and a decimation of 0.2 on both axes and interpolation
cv2.INTER_AREA
我在
版本
一个 (相反)输出:
I did a version in pyvips:
I can run it on your test image like this:
To make this (rather dark) output: