原图:
分块结果:
拼接结果:
代码:
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
def get_patch(img,patch_size):
imgs = []
h,w,n = img.shape
new_h, new_w = patch_size, patch_size
col=int(w/patch_size)+1
row=int(h/patch_size)+1
patch_n=col*row
top=0
for r in range(row):
foot=top+new_h
if foot>h:foot=h
left=0
for c in range(col):
right=left+new_w
if right >w:right=w
img_patch =img[top:foot,left:right]
left = left + new_w+1
imgs.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_c
else:
imgs_h=np.vstack((imgs_h,imgs_c))
return imgs_h
img=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()