[SciPy-user] masking large arrays

Emanuele Zattin emanuelez at gmail.com
Thu May 24 02:51:10 EDT 2007


On 5/24/07, Stefan van der Walt <stefan at sun.ac.za> wrote:
>
> On Thu, May 24, 2007 at 12:26:04AM +0200, Emanuele Zattin wrote:
> > Hello,
> > i have a function that gives me regional maxima of an image (1024x1024
> pixels).
> > the regional maxima matrix contains 1 where regional maxima are found
> and 0
> > elsewhere.
> > i would like to use this array to mask the initial image and then
> histogram it
> > in order to see how the values of the maxima are distributed.
> >
> > newimg = img[maxima]
>
> Is this roughly what you are trying to do?
>
> In [44]: x = N.random.random((3,3))
>
> In [45]: y = N.array([[0,1.,0],[1.,0,1],[0,0,1]])
>
> In [46]: x[y.astype(bool)]
> Out[46]: array([ 0.42440316,  0.29431396,  0.22774399,  0.78288364])
>
> You can apply the histogram function to the resulting values.


Actually what i was trying was to  get a matrix with zeros where zeros
appear in the mask (y in your example) and the value of the original array
where the mask is set to 1.
Right now i solved in some other way, but still i would be curious to know a
nice way to do that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20070524/ff72b407/attachment.html>


More information about the SciPy-User mailing list