Concatenating images (numpy arrays), but they look like HSV images

Robert Kern robert.kern at gmail.com
Thu Jul 9 20:08:08 CEST 2009


On 2009-07-09 12:34, Sebastian Schabe wrote:
> Hello everybody,
>
> I want to concatenate 2 numpy array which in fact are RGB images:
>
> def concat_images(im1,im2):
> rows1 = im1.shape[0]
> rows2 = im2.shape[0]
>
> if rows1 < rows2:
> im1 = concatenate((im1,zeros((rows2-rows1,im1.shape[1],3), int)), axis=0)
> elif rows1 > rows2:
> im2 = concatenate((im2,zeros((rows1-rows2,im2.shape[1],3), int)), axis=0)
>
> return concatenate((im1,im2), axis=1)
>
> It's all working fine, except that the images when showing with pylab
> are somewhat interpreted as HSV images as it looks. The function zeros()
> must be responsible for that circumstance, because when the arrays have
> the same shape and are concatenated they appear as horizontally
> concatenated images as I expected.
>
> Can someone help me with that?

Ask on the matplotlib mailing list.

   https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Probably, you need to use zeros(..., dtype=uint8). When you use dtype=int, that 
will result in dtype=int arrays. I suspect that matplotlib is then interpreting 
that to mean that you want it to treat the input as scalar data (which it will 
pass through a colormap) rather than an RGB image.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list