Skip to content

Instantly share code, notes, and snippets.

@derwiki
Created January 23, 2018 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derwiki/f640dc497392d365f36a446574cbd122 to your computer and use it in GitHub Desktop.
Save derwiki/f640dc497392d365f36a446574cbd122 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
filenames = ["file1.jpg", ... ]
columns = []
for i, filename in enumerate(filenames):
img: np.array = cv2.imread(f"p/{filename}")
height: int = len(img)
width: int = len(img[0])
column_start = 2 * i
column_end = 2 * i + 2
print(f"filename: {filename}, height: {height}, width: {width}, {column_start}-{column_end}")
column = img[0:height, column_start:column_end]
columns.append(column)
matrix = [[] for _ in range(height)]
for row_idx in range(height):
row = []
for col_idx in range(len(columns)):
pixels = columns[col_idx][row_idx]
matrix[row_idx] += list(pixels)
new_img = np.array([np.array(list(row)) for row in matrix])
cv2.imwrite('output.jpg', new_img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment