Python-numpy实现灰度图像的分块和合并方式
作者:weixin_38671006 时间:2021-06-14 16:24:27
我就废话不多说了,直接上代码吧!
from numpy import *
import numpy as np
import cv2, os, math, os.path
from PIL import Image
base="F:\\Spy_CNN\\pythonCode\\cvSPY\\cvTest\\LBP\\LBPImag3\\"
base2="F:\\ProgrameCode\\FaceDataLib\\orl_Arry\\"
imageOld=cv2.imread(base2+"s1_1.bmp")
image=cv2.cvtColor(imageOld,cv2.COLOR_BGR2GRAY)
'''图像的合成'''
H,W=image.shape#(112, 92)
kuai=5
a=1#为了好调程序
maskx,masky = H/kuai,W/kuai #29 14
toImage=np.zeros((H+(kuai-1)*a,W+(kuai-1)*a))
toImage.shape
#您画画图,总结规律,就可以想出来了
for i in range(kuai):
for j in range(kuai):
'''float64 array'''
faceZi=image[int(i*maskx): int((i+1)*maskx),int(j*masky) :int((j+1)*masky)]
cv2.imwrite(base+str(i)+str(j)+".bmp",faceZi)
# toImage[int(i*maskx)+a: int((i+1)*maskx)+a,int(j*masky)+a :int((j+1)*masky)+a]=faceZi
toImage[int(i*maskx)+i: int((i+1)*maskx)+i,int(j*masky)+j :int((j+1)*masky)+j]=faceZi
cv2.imwrite(base+"toImage.bmp",toImage)
#最简单的,直接在灰度图像上画出一条黑线,只是会丢失一些像素的数据
for i in range(1,kuai):
print(i)
toImage[int(i*maskx),:]=0
toImage[:,int(i*masky)]=0
cv2.imwrite(base+"toImage.bmp",toImage)
来源:https://blog.csdn.net/weixin_38671006/article/details/92787612
标签:Python,numpy,灰度图像,分块,合并
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python之父谈Python的未来形式
2022-02-05 11:10:42
python实现彩票系统
2021-04-12 21:16:42
使用python获取电脑的磁盘信息方法
2021-05-09 18:14:42
python使用smtplib模块发送邮件
2023-05-16 22:25:38
![](https://img.aspxhome.com/file/2023/7/87897_0s.jpg)
Jquery作者John Resig自己封装的javascript 常用函数
2023-09-11 13:14:16
设计师的职业规划
2009-08-31 12:52:00
使用python实现画AR模型时序图
2021-07-03 01:11:08
![](https://img.aspxhome.com/file/2023/8/66278_0s.jpg)
数据库理论:学习基于SQL数据库的算法
2009-01-13 13:38:00
Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案
2021-09-24 12:00:03
![](https://img.aspxhome.com/file/2023/4/72074_0s.png)
Python实现8种常用抽样方法
2023-02-01 18:03:19
![](https://img.aspxhome.com/file/2023/7/65487_0s.png)
基于Python制作公交车站查询系统
2022-10-03 04:34:03
![](https://img.aspxhome.com/file/2023/3/80423_0s.png)
Go语言变量与基础数据类型详情
2023-08-30 03:13:16
php环境下利用session防止页面重复刷新的具体实现
2023-11-14 08:51:45
asp将table生成excel文件(xls)
2011-03-07 11:17:00
Pycharm连接远程服务器过程图解
2023-07-25 04:37:53
![](https://img.aspxhome.com/file/2023/1/88991_0s.png)
25个出色的使用叶子的logo设计
2009-12-29 12:53:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/1113360-10s.jpg)
Python+OpenCV 实现简单的高斯滤波(推荐)
2021-07-18 20:31:26
![](https://img.aspxhome.com/file/2023/6/88936_0s.png)
JS中的THIS和WINDOW.EVENT.SRCELEMENT详解
2023-07-20 20:48:51
从 msxml6.dll 中获取 DOMDocument 对象的方法与属性
2009-02-22 18:46:00
css基础教程属性篇
2008-07-23 12:44:00
![](https://img.aspxhome.com/file/UploadPic/20087/23/200872312564485s.jpg)