1

I try to concatenate three images vertically and I need some assistance with the code/function. So far I imported one image and cropped 3 smaller images with the same size. Now I want to concatenate them in one image that will be long, but narrow. However, I can't find an appropriate function or even if I find one I get an error message when I apply it to my code.

I already tried to make a collection from my three pictures and then use the function skimage.io.concatenate_images(sf_collection), but this results in a 4-dimensional picture that cannot be visualized.

sf_collection = (img1,img2,img3)
concat_page = skimage.io.concatenate_images(sf_collection)

My expected output is the three images to be concatenated vertically in one image (very long and narrow).

dubbbdan
  • 2,650
  • 1
  • 25
  • 43
Nick
  • 67
  • 2
  • 9

2 Answers2

3

Ive never used skimage.io.concatenate, but I think you are looking for np.concatenate. It defaults to axis=0, but you can specify axis=1 for a horizontal stack. This also assumes you have already loaded the images into their array from.

from scipy.misc import face
import numpy as np
import matplotlib.pyplot as plt

face1 = face()
face2 = face()
face3 = face()

merge = np.concatenate((face1,face2,face3))

plt.gray()
plt.imshow(merge)

which returns: enter image description here

If you look at the skimage.io.concatenate_images docs, it's using np.concatenate too. It seems like that function provides a data structure to hold collections of images, but not merge into a single image.

dubbbdan
  • 2,650
  • 1
  • 25
  • 43
1

Like this:

import numpy as np

h, w = 100, 400

yellow = np.zeros((h,w,3),dtype=np.uint8) + np.array([255,255,0],dtype=np.uint8)
red    = np.zeros((h,w,3),dtype=np.uint8) + np.array([255,0,0],dtype=np.uint8)
blue   = np.zeros((h,w,3),dtype=np.uint8) + np.array([0,0,255],dtype=np.uint8)

# Stack vertically
result = np.vstack((yellow,red,blue))

enter image description here

Use the following to stack side-by-side (horizontally):

result = np.hstack((yellow,red,blue))
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432