# itk.GetArrayFromImage fail after source region size change.

**URL:** https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667
**Category:** Beginner Questions
**Created:** [February 10, 2018, 10:24am UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667 "2018-02-10T10:24:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [February 10, 2018, 10:24am UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/1 "2018-02-10T10:24:43Z")

</div>

I got an error after doing the following, it seems that after changing the source, itk.GetArrayFromImage no longer works, however .GetOutput() still works.

```
reader = itk.ImageSeriesReader[ItkTypes.IF3].New()
reader.SetFileNames(files)
reader.Update()

itk.GetArrayFromImage(reader.GetOutput())

reader.SetFileNames(newFiles)
reader.UpdateLargestPossibleRegion()

# Some Filter Down the Line
itk.GetArrayFromImage(someFilter.GetOutput()) # This Fails

```

This is the error I get:

```
File "/usr/local/Cellar/insighttoolkit/4.12.1/lib/python3.6/site-packages/itk/Configuration/../itkPyBufferPython.py", line 3120, in GetArrayViewFromImage
ndarrview = numpy.asarray(memview).view(dtype = numpydatatype).reshape(shape).view(numpy.ndarray)
ValueError: cannot reshape array of size 262144 into shape (23,512,512)

```

Anyone can help?

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [February 10, 2018, 2:35pm UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/2 "2018-02-10T14:35:55Z")

</div>

hmm looks like I managed to solve this by doing reader.Modified after setting FileNames. Am I doing this the right way?

hmm it seems that calling UpdateLargestPossibleRegion() at the end of the pipeline doesn’t propagate to all filters up. Do I need to call UpdateLargestPossibleRegion() in every single filter I’m my pipe? It seems like it only works if it do.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [February 10, 2018, 5:36pm UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/3 "2018-02-10T17:36:03Z")

</div>

Hi @benjaminhon,

Does this issue still occur with the latest version of ITK, 4.13?

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [February 11, 2018, 6:21am UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/4 "2018-02-11T06:21:26Z")

</div>

Hi matt, I’m currently on 4.12.1 installed using home-brew.

when I call UpdateLargestPossibleRegion() at the end of the pipeline, it seems that I can get itk.GetArrayFromImage from the end, but when I try to get some outputs from the middle of the pipeline, they give me that error.

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [February 11, 2018, 8:36am UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/5 "2018-02-11T08:36:06Z")

</div>

I just tried it on 4.13, seems like I still get the same error

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [February 11, 2018, 2:05pm UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/6 "2018-02-11T14:05:00Z")

</div>

> [@benjaminhon](#):
>
> when I call UpdateLargestPossibleRegion() at the end of the pipeline, it seems that I can get itk.GetArrayFromImage from the end

Yes, calling `UpdateLargestPossibleRegion()` is necessary to ensure that the image passed into `GetArrayFromImage()` has been populated appropriately. I will look into calling this automatically to avoid the need to call it manually.

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [February 11, 2018, 3:29pm UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/7 "2018-02-11T15:29:48Z")

</div>

Hi matt, I was further debugging and found out that it was an intermediate ExtractSlice filter that was changing all my RequestedRegion to 512 by 512 by 1. Such that when I call itk.GetArrayFromImage, I have to call UpdateLargestPossibleRegion() again.

My assumption was that ExtractSlice which I used as a split off filter off my main pipeline would not affect the upstream but it did.

I think I understand more now, will update if I find out anything again 🙂

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [February 11, 2018, 8:32pm UTC](https://discourse.itk.org/t/itk-getarrayfromimage-fail-after-source-region-size-change/667/8 "2018-02-11T20:32:18Z")

</div>

👍@benjaminhon yes, you got it.

To help other folks from being caught by this gotcha, [this proposed patch](http://review.source.kitware.com/#/c/23167) will call `UpdateLargestPossibleRegion` before converting the image to a NumPy array.
