Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


sebastian.schabe at gmx

Jul 9, 2009, 10:34 AM

Post #1 of 3 (387 views)
Permalink
Concatenating images (numpy arrays), but they look like HSV images

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?

Thanks a lot,
Basti
--
http://mail.python.org/mailman/listinfo/python-list


robert.kern at gmail

Jul 9, 2009, 11:08 AM

Post #2 of 3 (367 views)
Permalink
Re: Concatenating images (numpy arrays), but they look like HSV images [In reply to]

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

--
http://mail.python.org/mailman/listinfo/python-list


sebastian.schabe at gmx

Jul 10, 2009, 3:01 AM

Post #3 of 3 (362 views)
Permalink
Re: Concatenating images (numpy arrays), but they look like HSV images [In reply to]

Robert Kern schrieb:
> 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.
>

Thanks Robert, that was exactly the problem. Now I'am really wondering
how one can know such details. Well, with your answer I searched again
in the mathplotlib documentation and under the function imshow(X, ...) I
indeed found the hint, that X has to be an uint8 or float array or PIL
image, but before I hadn't known where to search.

So again, thank you

Sebastian
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.