溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Python-numpy如何實現灰度圖像的分塊和合并方式

發布時間:2021-05-28 10:50:44 來源:億速云 閱讀:218 作者:小新 欄目:開發技術

小編給大家分享一下Python-numpy如何實現灰度圖像的分塊和合并方式,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

直接上代碼

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)

看完了這篇文章,相信你對“Python-numpy如何實現灰度圖像的分塊和合并方式”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女