资源简介
图片的旋转方法算法以及双线性插值,最邻近插值法
图片的旋转方法算法以及双线性插值,最邻近插值法
代码片段和文件信息
from PIL import Image
import numpy as np
def shear(imgshxshy):
shx=0.5
shy=0.5
desImg = Image.new(img.mode(int(img.width + shx*img.height)int(img.width * shy + img.height)))
print(img.size)
convertMatrix = [[1shx0][shy10][001]]
for x in range(img.width):
for y in range(img.height):
color = img.getpixel((xy))
pos = [xy1]
pos_convert = np.dot(convertMatrixpos)
#print(pos_convert)
desImg.putpixel((int(pos_convert[0])int(pos_convert[1]))color)
return desImg
def Bilinear_interpolation(imgSrcdesImgposJudgeoriginPos):
if (imgSrc.width > originPos[0] + 1 and imgSrc.height > originPos[1] + 1) and (originPos>=0).all():
x_low = np.floor(originPos[0])
x_up = np.ceil(originPos[0])
y_low = np.floor(originPos[1])
y_up = np.ceil(originPos[1])
s = originPos[0] - x_low
t = originPos[1] - y_low
try:
p1 = np.array(imgSrc.getpixel((x_lowy_low)))
p2 = np.array(imgSrc.getpixel((x_upy_low)))
p3 = np.array(imgSrc.getpixel((x_lowy_up)))
p4 = np.array(imgSrc.getpixel((x_upy_up)))
colorReal = np.array((1-s)*(1-t)*p1+(1-s)*t*p3+(1-t)*s*p2+s*t*p4dtype=“int“)
desImg.putpixel((posJudge[0]posJudge[1])tuple(colorReal))
except:
print(x_low“ “x_up “ “y_low“ “y_up“ “originPos)
def nearest(imgSrcdesImgposJudgeoriginPos):
if (imgSrc.width > originPos[0] + 1 and imgSrc.height > originPos[1] + 1) and (originPos>=0).all():
x_low = np.floor(originPos[0])
x_up = np.ceil(originPos[0])
y_low = np.floor(originPos[1])
y_up = np.ceil(originPos[1])
#需要获取的像素的位置
x_get = 0
y_get = 0
if originPos[0] - x_low>=0.5:
x_get = x_up
else:
x_get = x_low
if originPos[1] - y_low>=0.5:
y_get=y_up
else:
y_get=y_low
try:
colorReal = np.array(imgSrc.getpixel((x_gety_get)))
desImg.putpixel((posJudge[0]posJudge[1])tuple(colorReal))
except:
print(x_low“ “x_up “ “y_low“ “y_up“ “originPos)
def rotate(imgangle):
#maxEdge = int(np.sqrt(img.width ** 2 + img.height ** 2))
beta = angle/180 * np.pi
newWidth = int(img.width * np.cos(beta) + img.height * np.sin(beta))
newHeight = int(img.width * np.sin(beta) + img.height * np.cos(beta))
desImg = Image.new(img.mode(newWidthnewHeight))
#print(desImg.size)
convertMatrix = [[np.cos(beta)-np.sin(beta)0][np.sin(beta)np.cos(beta)0][001]]
#m其实是为了乘上pos使得以图片中心点为原点的,但本身前面还要乘 convertMatrix,所以在前面先乘好
m = [[10-img.width/2] [01-img.height/2]
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论