Whilst trying to reverse the process of this question by joining smaller images together to assemble the original one. I've put this code together.
# imgarr is a list of image filenames.
# w & h are the number of tiles used for width & height
# folder the destination folder
def tiles_to_image(imgarr, w, h, folder):
# concatenates images
im_h = cv2.hconcat(imgarr)
nuimg = chunks(imgarr, w)
img_tile = concat_vh(nuimg)
# write the output image
imgFile = os.path.join(folder, "image.jpeg")
cv2.imwrite(imgFile, img_tile)
def concat_vh(list_2d):
# return final image
return cv2.vconcat([cv2.hconcat(list_h)
for list_h in list_2d])
def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]
The code works fine, however in the reconstruction the images are altered, presumably stretched but then resized down. See this close up of a yellow image with single pixel diagonal lines. Not the introduction of pink anti-aliasing on the right image. #notusinglenna
The source images must not be altered. I'm not sure how to stop this since there are no options for hconcat
. I realise there may be a better way to reconstruct an image like this.