Python-OpenCV 图像采样

Python-OpenCV 图像采样,第1张

import math
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread(r"C:\Users\Dennis\Desktop\python.jpeg")
height, width = img.shape[0:2]
# 将图像整除分割为16 * 16个区域
numHeight, numWidth = int(height/16), int(width/16)
new_img = np.zeros((height, width, 3), np.uint8)

for i in range(16):
    # 获取每个分割区域左上角的y坐标
    y = i * numHeight
    for j in range(16):
        # 获取每个分割区域左上角的x坐标
        x = j * numWidth
        #采样
        b = img[y, x, 0]
        g = img[y, x, 1]
        r = img[y, x, 2]
        for n in range(numHeight):
            for m in range(numWidth):
                # 用每个分割区域左上角的bgr值来赋给整个区域
                new_img[y + n, x + m, 0] = np.uint8(b)
                new_img[y + n, x + m, 1] = np.uint8(g)
                new_img[y + n, x + m, 2] = np.uint8(r)
cv2.imshow("1", img)
cv2.imshow("2", new_img)
cv2.waitKey(0)

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/731132.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存