# how can i use iterators in simpleITK python?

**URL:** https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363
**Category:** Uncategorized
**Created:** [August 5, 2020, 4:20am UTC](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363 "2020-08-05T04:20:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![unicorn](https://discourse.itk.org/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@unicorn](https://discourse.itk.org/u/unicorn)
#### Post date: [August 5, 2020, 4:20am UTC](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363/1 "2020-08-05T04:20:43Z")

</div>

I worked on iterators in ITK. I wonder if there is any way to use them in simpleITK? If not, what is the alternative?  
For example, I want to write compare two images and compute some similarity measure(in my case it is normalised cross-correlation). So in order to implement this, I would be requiring iterators right?  
Also please let me know if there is any method built-in sitk to compute normalised cross correction directly without writing code by myself

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 5, 2020, 1:03pm UTC](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363/2 "2020-08-05T13:03:35Z")

</div>

Hello @unicorn,

Similar to [the answer](https://discourse.itk.org/t/metric-to-compare-two-images-using-simpleitk/3351) to your previous question. The various similarity measures are listed in the SimpleITK documentation (one of them is normalized cross-correlation).

If you want to perform computations using all pixels, iterating is best avoided.  
We highly recommend using a broadcasting approach, applying operations to the whole image in one go, same as when working with numpy and most other Python tools (e.g. `sitk.Square(img1-img2)`).

If you are more comfortable using numpy then you can just get views of the image data and work in numpy:

```auto
arr1 = sitk.GetArrayViewFromImage(img1)
arr2 = sitk.GetArrayViewFromImage(img2)
(arr1-arr2)**2

```
