Numpy Stacking

水平、橫向合併

  • numpy.hstack((a, b))
  • numpy.concatenate((a, b), axis=1)
  • numpy.column_stack((a, b))

垂直、直立合併

  • numpy.vstack((a, b))
  • numpy.concatenate((a, b), axis=0)
  • numpy.row_stack((a, b))

深度合併

  • numpy.dstack((a, b))
import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load the two sample images
image1 = cv2.imread('space/1.jpg')
image2 = cv2.imread('space/2.jpg')

# Convert images to grayscale (optional)
image1_gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
image2_gray = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)

# Perform image stitching (depth-wise stacking)
stitched_image = np.dstack((image1_gray, image2_gray))

# Plot the original images
plt.figure(figsize=(12, 6))

plt.subplot(2, 2, 1)
plt.imshow(cv2.cvtColor(image1, cv2.COLOR_BGR2RGB))
plt.title('Image 1')

plt.subplot(2, 2, 2)
plt.imshow(cv2.cvtColor(image2, cv2.COLOR_BGR2RGB))
plt.title('Image 2')

# Plot one channel of the stitched image (for visualization)
plt.subplot(2, 2, 3)
plt.imshow(stitched_image[:, :, 0], cmap='gray')  # Display the first channel
plt.title('Stitched Image (Channel 0)')

# Plot one channel of the stitched image (for visualization)
plt.subplot(2, 2, 4)
plt.imshow(stitched_image[:, :, 1], cmap='gray')  # Display the first channel
plt.title('Stitched Image (Channel 1)')

plt.tight_layout()
plt.show()
分類: 未分類,標籤: 。這篇內容的永久連結

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *