做网站买什么书,sql数据库做的网站怎么发布,济南市工程建设标准定额站网站,wordpress增加评论验证码OpenCV中的resize函数可以对图像做任意比例的放大(/缩小)处理#xff0c;该处理过程会对图像做高斯模糊化以保证图像在进行放大#xff08;/缩小#xff09;后尽可能保留源图像所展现的具体内容#xff08;消除固定频率插值/采样带来的香农采样信息损失#xff09;#x…OpenCV中的resize函数可以对图像做任意比例的放大(/缩小)处理该处理过程会对图像做高斯模糊化以保证图像在进行放大/缩小后尽可能保留源图像所展现的具体内容消除固定频率插值/采样带来的香农采样信息损失但在有些场景中该方法不适用如部分应用场景只为了展现图像具体像素的色彩信息则其就不需要对具体输入的图像做高斯平滑处理则此场景需要自行实现实现代码如下
def enlarge_without_gauss(img, ratio:int):h,w img.shapeimg_x_ratio np.zeros((img.shape[0]*ratio, img.shape[1]*ratio), dtypenp.uint8)for h in range(img.shape[0]):for w in range(img.shape[1]):img_x_ratio[h*ratio:h*ratioratio, w*ratio:w*ratioratio] img[h,w]return img_x_ratio
与OpenCV自带的resize函数放大对比简易比较代码如下
import numpy as np
import cv2def enlarge_without_gauss(img, ratio:int):h,w img.shapeimg_x_ratio np.zeros((img.shape[0]*ratio, img.shape[1]*ratio), dtypenp.uint8)for h in range(img.shape[0]):for w in range(img.shape[1]):img_x_ratio[h*ratio:h*ratioratio, w*ratio:w*ratioratio] 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倍