Mak*_*gan 0 python opencv image image-processing
我有一个图像 A。目标是将其缩小为图像,使图像的尺寸更小,但新图像中的像素不包含原始图像中不存在的值。换句话说,如果 $p \in A'$ 那么 $p \in A$。
我尝试在 python 中执行此操作,如下所示:
resized = cv2.resize(old_img, (1024, 1024), 0, 0, cv2.INTER_NEAREST)
Run Code Online (Sandbox Code Playgroud)
但是,当输入是二值图像(old_img 仅包含黑白像素)时,生成的图像包含灰度值(值不等于 0 或 255)。
这是实现中的错误吗?对我来说,没有像素以非原始值结束是一个硬性要求。
I believe it should be
resized = cv2.resize(old_img, (1024, 1024), 0, 0, interpolation = cv2.INTER_NEAREST)
Run Code Online (Sandbox Code Playgroud)
Note the interpolation = ...
as part of the 3rd argument.
See here