目录

OpenCV单通道图像按像素成倍比例放大(无高斯平滑处理)

OpenCV中的resize函数可以对图像做任意比例的放大(/缩小)处理,该处理过程会对图像做高斯模糊化以保证图像在进行放大(/缩小)后尽可能保留源图像所展现的具体内容(消除固定频率插值/采样带来的香农采样信息损失),但在有些场景中该方法不适用,如:部分应用场景只为了展现图像具体像素的色彩信息,则其就不需要对具体输入的图像做高斯平滑处理,则此场景需要自行实现,实现代码如下:

python 复制代码
def enlarge_without_gauss(img, ratio:int):
    h,w = img.shape
    img_x_ratio = np.zeros((img.shape[0]*ratio, img.shape[1]*ratio), dtype=np.uint8)
    for h in range(img.shape[0]):
        for w in range(img.shape[1]):
            img_x_ratio[h*ratio:h*ratio+ratio, w*ratio:w*ratio+ratio] = img[h,w]
    return img_x_ratio

与OpenCV自带的resize函数放大对比简易比较代码如下:

python 复制代码
import numpy as np
import cv2

def enlarge_without_gauss(img, ratio:int):
    h,w = img.shape
    img_x_ratio = np.zeros((img.shape[0]*ratio, img.shape[1]*ratio), dtype=np.uint8)
    for h in range(img.shape[0]):
        for w in range(img.shape[1]):
            img_x_ratio[h*ratio:h*ratio+ratio, w*ratio:w*ratio+ratio] = img[h,w]
    return img_x_ratio

# 随机产生一张单通道图像
img = np.random.rand(80, 120)
img = (img * 255).astype(np.uint8)
cv2.imshow("img", img)

# 设置缩放比例
RATIO = 8

# 按具体像素位放大
img_enlarge_xN_without_gauss = enlarge_without_gauss(img, RATIO)
cv2.imshow("enlarge_xN_without_gauss", img_enlarge_xN_without_gauss)

# 使用opencv自带函数resize放大
h, w = img.shape
img_resize_xN = cv2.resize(img, (w*RATIO, h*RATIO))
cv2.imshow("resize_xN", img_resize_xN)

cv2.waitKey(0)

随机产生的原图如下:

按像素放大效果(设置的8倍):

使用opencv resize函数放大(设置的8倍):

本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
www_pp_2 小时前
# 使用 Dlib 和 OpenCV 实现基于深度学习的人脸检测
人工智能·深度学习·opencv
啥都鼓捣的小yao5 小时前
利用C++编写操作OpenCV常用操作
开发语言·c++·opencv
Milton8 小时前
图像处理中的 Gaussina Blur 和 SIFT 算法
opencv·sift·computer graphics
西红柿土豆丶12 小时前
人脸考勤管理一体化系统(人脸识别系统,签到打卡)
python·深度学习·opencv·人脸识别·人脸识别系统·考勤管理系统·签到打卡
一大Cpp12 小时前
随笔1 认识编译命令
linux·opencv·ubuntu
巷95512 小时前
OpenCV轮廓检测全面解析:从基础到高级应用
人工智能·opencv·计算机视觉
欣然~14 小时前
OpenCV 在树莓派上进行实时人脸检测
人工智能·opencv·计算机视觉
秣厉科技15 小时前
【秣厉科技】LabVIEW工具包——OpenCV 教程(18):highgui 模块
科技·opencv·labview
www_pp_1 天前
# 基于 OpenCV 的人脸识别实战:从基础到进阶
人工智能·opencv·计算机视觉
蹦蹦跳跳真可爱5891 天前
Python----计算机视觉处理(Opencv:道路检测之车道线拟合)
开发语言·人工智能·python·opencv·计算机视觉