原图:
分块结果:
拼接结果:
代码:
import numpy as np
import cv2 as cv
import matplotlib.pyplot as pltdef get_patch(img,patch_size):imgs = []h,w,n = img.shapenew_h, new_w = patch_size, patch_sizecol=int(w/patch_size)+1row=int(h/patch_size)+1patch_n=col*rowtop=0for r in range(row):foot=top+new_hif foot>h:foot=hleft=0for c in range(col):right=left+new_wif right >w:right=wimg_patch =img[top:foot,left:right]left = left + new_w+1imgs.append(img_patch)# a[r][c].imshow(img_patch)top = top + new_h+1# plt.show()return imgs,row,col
def jointImage(imgs,h_n,w_n,):for h in range(h_n):# 按行拼接for w in range(w_n):# 按列拼接if w==0:imgs_c=np.array(imgs[h*w_n+w])else:img_c=np.array(imgs[h*w_n+w])imgs_c=np.hstack((imgs_c,img_c))print(imgs[h * w_n + w].shape)if h==0:imgs_h=imgs_celse:imgs_h=np.vstack((imgs_h,imgs_c))return imgs_himg=cv.imread('./SIDD-Small Dataset/SIDD_Small_sRGB_Only/SIDD_Small_sRGB_Only/Data/0001_001_S6_00100_00060_3200_L/GT_SRGB_010.PNG')
imgs,h_n,w_n=get_patch(img,1024)
plt.rcParams["figure.figsize"] = [10, 8]
fig, axes = plt.subplots(nrows=h_n, ncols=w_n)
num=0
for r in range(h_n):for c in range(w_n):axes[r, c].imshow(imgs[num])num+=1
# plt.tight_layout()
plt.subplots_adjust(bottom=-.1, right=0.5, top=.8)
plt.show()
full_img=jointImage(imgs,h_n,w_n)
plt.title('full_img')
plt.imshow(full_img)
plt.show()