问题描述
我有一个大小为 1044*1408 的图像 F
,它只有 3 个整数值 0、2 和 3.
I have an image F
of size 1044*1408, it only has 3 integer values 0, 2, and 3.
我想把它缩小到 360*480.现在我使用 Z= cv2.resize(F,(480,380))
.但是 Z
是内插的,它有许多唯一值,不仅仅是 0、2 和 3.我不能只是将内插值四舍五入到最接近的整数,因为我会得到一些 1.
I want to shrink it to 360*480. Now I am using Z= cv2.resize(F,(480,380))
. But Z
is interpolated, it has many unique values, more than just 0, 2 and 3. I can't just round up the interpolated values to the closest integer, because I will get some 1s.
F
从 tif 文件中读取并操作,现在是一个 ndarray.所以我不能使用 PIL: F = F.resize((new_width, new_height))
因为 F
不是来自 F = Image.open(*).
F
is read from a tif file and manipulated, it is an ndarray now. So I can't use PIL: F = F.resize((new_width, new_height))
as F
is not from F = Image.open(*)
.
推荐答案
您可以使用
INTER_NEAREST
:
Z= cv2.resize(F,(480,380),fx=0, fy=0, interpolation = cv2.INTER_NEAREST)
这篇关于无需插值即可缩小/调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!