title: Creating a mosaic of thumbnails with OpenCV 3 and numpy
body: <p>I have a list of thumbnails all of the same size and I want to show them as a mosaic with a given width. The idea is to create a single image for each row with shape <code>(thumb_height, thumb_width*width, 3)</code> and then concatenate them all together by obtaining a single image. Now, if the width is not a divisor of the number of thumbnails the last row will miss some images. The idea is to fill the gap with a black placeholder. Here's the code:</p>
  
  <pre><code>def show_images_mosaic(images, width):
      rows = []
      for i in range(0, len(images), width):
          rows.append(np.concatenate(images[i: i + width], axis=1))
  
      if len(rows) &gt; 1:
          last_row = rows[-1]
  
          height = images[0].shape[0]
          last_row_width = last_row.shape[1]
          expected_width = rows[0].shape[1]
  
          if last_row_width &lt; expected_width:
              filler = np.zeros((height, expected_width - last_row_width, 3))
              rows[-1] = np.concatenate((last_row, filler), axis=1)
          else:
              filler = None
  
      mosaic = np.concatenate(rows, axis=0)
      cv2.imshow('Mosaic', mosaic)
  
      for i, row in enumerate(rows):
          cv2.imshow('Row' + str(i), row)
  
      cv2.imshow('LastRowUnfilled', last_row)
      if filler is not None:
          cv2.imshow('Filler', filler)
  
      cv2.waitKey(0)
  </code></pre>
  
  <p>This code works great if <code>width</code> is a divisor of the number of thumbnails. But for some reason it breaks when I have to fill the last row. The weird thing is that it doesn't break only the last row, but it breaks the whole image and I really can't understand why. Additionally the single rows except for the last one are correctly shown, but the whole mosaic is broken as if the last row affects the whole image.</p>