# Mask (ROI) as NumPy array

**URL:** https://discourse.itk.org/t/mask-roi-as-numpy-array/2933
**Category:** Beginner Questions
**Created:** [April 12, 2020, 12:41am UTC](https://discourse.itk.org/t/mask-roi-as-numpy-array/2933 "2020-04-12T00:41:47Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)
#### Post date: [April 16, 2020, 1:41pm UTC](https://discourse.itk.org/t/mask-roi-as-numpy-array/2933/8 "2020-04-16T13:41:03Z")

</div>

> [@blowekamp](#):
>
> The proposed solution, which uses a numpy mask, or `numpy.extract` have the additional memory and computational time on the order of the number of pixels.

For reference, for a 512^3 16-bit volume with a fairly large mask, numpy provides result in a fraction of a second (around 200msec). Interestingly, `np.extract` is about 50% slower than direct array indexing `image[condition]`.

So, using numpy for image masking is indeed much slower than ITK but still good enough for many use cases.

---

_[View the full topic](https://discourse.itk.org/t/mask-roi-as-numpy-array/2933)._
