pythonpictureanalysis/Blue_noise_sampling.py
2022-07-26 21:27:11 +08:00

51 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# @Time : 2022-7-26 0026 19:09
# @Author : Qing
# @Email : derighoid@gmail.com
# @File : Blue_noise_sampling.py
# @Software: PyCharm
'''
计算新图形(放大后或缩小后)的坐标点像素值对应于原图像中哪一个像素点填充的。
src是原图dst是新图原来的图像宽度/高度除以新图像的宽度/高度可以得到缩放比例假如是缩小图片括号内的数字小于1放大则大于1相当于系数再乘以新图片的宽度/高度,就实现了缩放。
'''
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import math
# # 最近邻插值算法
# # dstH为新图的高;dstW为新图的宽
# def blueNoiseSampl(img, dstH, dstW):
# scrH, scrW, t = img.shape # src原图的长宽
# retimg = np.zeros((dstH, dstW, 3), dtype=np.uint8)
# for i in range(dstH - 1):
# for j in range(dstW - 1):
# scrx = round(i * (scrH / dstH))
# scry = round(j * (scrW / dstW))
# retimg[i, j] = img[scrx, scry]
#
# return retimg
#
#
# im_path = './data/th.png'
# image = np.array(Image.open(im_path))
#
# plt.figure(figsize=(16, 8))
#
# plt.subplot(1, 2, 1)
# plt.imshow(image)
#
# image1 = blueNoiseSampl(image, image.shape[0] * 2, image.shape[1] * 2)
# # 从array转换成image
# image1 = Image.fromarray(image1.astype('uint8')).convert('RGB')
# image1.save('./data/picture13.png')
# plt.subplot(1, 2, 2)
# plt.imshow(image1)
# plt.show()