假設我們有一個影像,它垂直分成 4 個子影像。分割后,我們打亂子影像。如何從子影像中獲取原始影像?或者,即使我們不知道順序,我們如何正確排序子影像以獲得原始影像?

uj5u.com熱心網友回復:
根據您分割影像的方式,一種解決方案是將影像的原始索引/位置保存在一個元組中。一旦它們被打亂,你就可以根據這個索引對影像串列進行排序,以恢復原始順序。然后使用hconcat將它們縫合在一起。
import cv2
img = cv2.imread('img.png')
img_list = []
# split image in half
img_B = img_list.append((1, img[:, img.shape[1]//2:]))
img_A = img_list.append((0, img[:, :img.shape[1]//2]))
# img_list is in order 1, 0
sorted_list = sorted(img_list, key=lambda x: x[0])
# sorted to correct order of 0, 1
result = cv2.hconcat([sorted_list[0][1], sorted_list[1][1]])
uj5u.com熱心網友回復:
假設您知道影像分割的順序,您可以使用 hconcat() 將它們連接回來
# horizontally concatenates images
# of same height
im_h = cv2.hconcat([imgA, imgB])
# show the output image
cv2.imshow('man_image.jpeg', im_h)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/364938.html
標籤:Python opencv 图像处理 蟒蛇成像库 scikit-image
