[Numpy-discussion] Downsampling array, retaining min and max values in window
Mon Jul 30 13:33:28 CDT 2007
Matthieu Brucher wrote:
> I think you should look into scipy.ndimage which has minimum_filter
> and maximum_filter
> 2007/7/24, Ludwig M Brinckmann < firstname.lastname@example.org
> Hi there,
> I have a large array, lets say 40000 * 512, which I need to
> downsample by a factor of 4 in the y direction, by factor 3 in the
> x direction, so that my resulting arrays are 10000 * 170 (or 171
> this does not matter very much) - but of all the values I will
> need to retain in the downsampled arrays the minimum and maximum
> of the original data, rather than computing an average or just
> picking every third/fourth value in the array.
> So essentially I have a 4*3 window, for which I need the min and
> max in this window, and store the result of applying this window
> to the original array as my results.
> What is the best way to do this?
order_filter(a, domain, order)
Perform an order filter on an N-dimensional array.
Perform an order filter on the array in. The domain argument acts
mask centered over each pixel. The non-zero elements of domain are
used to select elements surrounding each input pixel which are placed
in a list. The list is sorted, and the output for that pixel is the
element corresponding to rank in the sorted list.
in -- an N-dimensional input array.
domain -- a mask array with the same number of dimensions as in. Each
dimension should have an odd number of elements.
rank -- an non-negative integer which selects the element from the
sorted list (0 corresponds to the largest element, 1 is the
next largest element, etc.)
out -- the results of the order filter in an array with the same
shape as in.
Run the order filter and then select out every 4th element in the first
dimension and 3rd element
mask = numpy.ones(4,3)
out = scipy.signal.order_filter(in, mask, 0)
new = out[::4,::3]
More information about the Numpy-discussion