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

2009-07-10 Thread Sebastian Schabe

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


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

2009-07-09 Thread Sebastian Schabe

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


Re: deleting certain entries in numpy array

2009-07-02 Thread Sebastian Schabe

Robert Kern schrieb:
First, convert the pos array to integers, and just the columns with 
indices in them:


  ipos = pos[:,:2].astype(int)

Now check the values in the mask corresponding to these positions:

  mask_values = mask[ipos[:,0], ipos[:,1]]

Now extract the rows from the original pos array where mask_values is 
nonzero:


  result = pos[mask_values != 0]



Great!!! That's the way I wanted.

After reading the numpy reference guide I supposed the delete function 
was not the right way, but that it's all about cerrect indexing. But I 
didn't really know how.


So thanks a lot, also to Ben.

>
> You will want to ask numpy questions on the numpy mailing list.
>
>   http://www.scipy.org/Mailing_Lists
>

I ever thought news-groups are the right way for questions like this. 
And the mailing list page just confuses me, but I'm trying to get used 
to it.



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


deleting certain entries in numpy array

2009-07-01 Thread Sebastian Schabe

Hello everybody,

I'm new to python and numpy and have a little/special problem:

I have an numpy array which is in fact a gray scale image mask, e.g.:

mask =
array([[  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0, 255, 255, 255,   0,   0, 255,   0],
   [  0,   0, 255, 255, 255,   0,   0, 255,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0],
   [  0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)

and I have another array of (y, x) positions in that mask (first two 
values of each row):


pos =
array([[  3.,   2.,   0.,   0.],
   [  3.,   4.,   0.,   0.],
   [  5.,   2.,   0.,   0.],
   [  5.,   4.,   0.,   0.],
   [  6.,   2.,   0.,   0.],
   [  6.,   7.,   0.,   0.],
   [  0.,   0.,   0.,   0.],
   [  8.,   8.,   0.,   0.]])

and now I only want to keep all lines from 2nd array pos with those 
indices that are nonzero in the mask, i.e. line 3-6 (pos[2]-pos[5]).


F.e. line 4 in pos has the values (5, 4) and mask[5][4] is nonzero, so I 
want to keep it. While line 2 (pos[1]) has the values (4, 6) and 
mask[4][6] is zero, so shall be discarded.


I want to avoid a for loop (if possible!!!) cause I think (but don't 
know) numpy array are handled in another way. I think numpy.delete is 
the right function for discarding the values, but I don't know how to 
build the indices.




Maybe someone can help me with that or suggest which way to do this

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