赞
踩
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 09:48:06 2020
@author: 张若昀的对象
"""
from PIL import Image;
import numpy as np;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
img2=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和2.jpg")
im_new=img1.copy()
width,height=img1.size
for i in range(width):
for j in range(height):
r1,g1,b1=img1.getpixel((i,j))
r2,g2,b2=img2.getpixel((i,j))
im_new.putpixel((i,j),(int(r1*0.3+r2*0.7),int(g1*0.3+g2*0.7),int(b1*0.3+b2*0.7)))
im_new.show()
悄悄整个美图(我觉得挺好看的嘻嘻 乡下的傍晚挺美的
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 09:48:06 2020
@author: 张若昀的对象
"""
from PIL import Image;
import numpy as np;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-差1.jpg")
img2=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-差2.jpg")
im_new=img1.copy()
width,height=img1.size
for i in range(width):
for j in range(height):
r1,g1,b1=img1.getpixel((i,j))
r2,g2,b2=img2.getpixel((i,j))
im_new.putpixel((i,j),(int(r1*2-r2),int(g1*2-g2),int(b1*2-b2)))
im_new.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 09:48:06 2020
@author: 张若昀的对象
"""
from PIL import Image;
import numpy as np;
import math;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-乘1.jpg")
img2=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-乘2.jpg")
im_new=img1.copy()
width,height=img1.size
for i in range(width):
for j in range(height):
r1,g1,b1=img1.getpixel((i,j))
r2,g2,b2=img2.getpixel((i,j))
im_new.putpixel((i,j),(int(r1*r2/255),int(g1*g2/255),int(b1*b2/255)))
im_new.show()
向前映射:遍历原图像各像素点的下标,计算改点在结果图像上位置,并赋值过去。
向后映射:遍历结果图像个像素点的下标,计算该点在原始图像上的对应像素点,并赋值过来。(多用向后映射)
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 9 09:34:15 2020
@author: 张若昀的对象
"""
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\lena_256.bmp")
dx,dy=-50,50
im_new=Image.new("L",img1.size,255)
width,height=im_new.size
for i in range(width):
for j in range(height):
if(i-dx>=0 and j-dy>=0 and i-dx<width and j-dy<height):
r1=img1.getpixel((i-dx,j-dy))
r2=r1
im_new.putpixel((i,j),(r2))
im_new.show()
img1.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 9 09:34:15 2020
@author: 张若昀的对象
"""
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
dx,dy=-50,50
im_new=Image.new("RGB",img1.size,(255,255,255))
width,height=im_new.size
for i in range(width):
for j in range(height):
if(i-dx>=0 and j-dy>=0 and i-dx<width and j-dy<height):
r1,g1,b1=img1.getpixel((i-dx,j-dy))
r2,g2,b2=r1,g1,b1
im_new.putpixel((i,j),(r2,g2,b2))
im_new.show()
img1.show()
**# -*- coding: utf-8 -*-
"""
Created on Thu Apr 9 09:34:15 2020
@author: 张若昀的对象
"""
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
dx,dy=-50,50
im_new=Image.new("RGB",img1.size,(255,255,255))
width,height=im_new.size
for i in range(width):
for j in range(height):
#if(i-dx>=0 and j-dy>=0 and i-dx<width and j-dy<height):
r1,g1,b1=img1.getpixel((width-i-1,j))
r2,g2,b2=r1,g1,b1
im_new.putpixel((i,j),(r2,g2,b2))
im_new.show()
img1.show()
**
一个点无限放大后会变成马赛克;
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 08:58:38 2020
@author: 张若昀的对象
"""
##放大
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
x,y=1.5,1.2
width,height=img1.size
im_new=Image.new("RGB",(int(width*x)+1,int(height*y)+1),(255,255,255))
for i in range(int(width*x)+1):
for j in range(int(height*y)+1):
r1,g1,b1=img1.getpixel((int(i/x),int(j/y)))
im_new.putpixel((i,j),(r1,g1,b1))
im_new.show()
img1.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 08:58:38 2020
@author: 张若昀的对象
"""
##缩小
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
x,y=0.5,0.4
width,height=img1.size
im_new=Image.new("RGB",(int(width*x)+1,int(height*y)+1),(255,255,255))
for i in range(int(width*x)+1):
for j in range(int(height*y)+1):
r1,g1,b1=img1.getpixel((int(i/x),int(j/y)))
im_new.putpixel((i,j),(r1,g1,b1))
im_new.show()
img1.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 09:45:08 2020
@author: 张若昀的对象
"""
import math;
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
x=math.pi*30/180;
width,height=img1.size
im_new=Image.new("RGB",img1.size,(255,255,255))
for i in range(width):
for j in range(height):
a=int(i*math.cos(x)-j*math.sin(x))
b=int(i*math.sin(x)+j*math.cos(x))
if a>=0 and a<width and b>=0 and b<height:
r1,g1,b1=img1.getpixel((a,b))
im_new.putpixel((i,j),(r1,g1,b1))
im_new.show()
img1.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 10:18:44 2020
@author: 张若昀的对象
"""
from PIL import Image;
img1=Image.open(r"C:\课堂\数字图像处理\实验参考图像\实验参考图像\合成-和1.jpg")
#垂直错切的比例
x=0.3;
width,height=img1.size
#新建图片
im_new=Image.new("RGB",(width,int(height+width*x)),(255,255,255))
for i in range(width):
for j in range(int(height+width*x)):
#向后映射的坐标变换
if j-x*i>=0 and j-x*i<height:
r1,g1,b1=img1.getpixel((i,int(j-x*i)))
im_new.putpixel((i,j),(r1,g1,b1))
im_new.show()
img1.show()
高老师人也太好了吧1551太好了怎么会有这么照顾同学的老师呢
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。