|
1 | 1 | :name: ConvertNumPyArrayToitkImage
|
2 | 2 |
|
3 | 3 | Interface ITK with NumPy Array
|
4 |
| -============================= |
| 4 | +=============================== |
5 | 5 |
|
6 | 6 | .. index::
|
7 | 7 | single: Image
|
8 |
| - single: instantiate |
9 | 8 |
|
10 | 9 | Synopsis
|
11 | 10 | --------
|
12 | 11 |
|
13 |
| -This example illustrates interfacing ITK Image data with NumPy array. While doing this, there are two key issues to |
14 |
| -to keep in mind. One, the order of indexes is different between ITK image data class and NumPy array. |
15 |
| -Second, there are two ways to access ITK image data as a NumPy array. i) Get direct access to memory with the data called |
16 |
| -"View" functions (array_view_from_image and image_view_from_array), or ii) Copy the data (array_from_image and image_from_array). |
17 |
| -If the view functions are used, the data can't be modified. |
| 12 | +This example illustrates interfacing ITK Image data with NumPy array. |
| 13 | +While doing this, there are two key issues to keep in mind. One, the order of |
| 14 | +indexes is different between ITK image data class and NumPy array. |
| 15 | +Second, there are two ways to access ITK image data as a NumPy array. |
| 16 | +i) Get direct access to memory with the data called"View" functions, or |
| 17 | +ii) Copy the data using array_from_image function. If the view functions are used, |
| 18 | +the data can't be modified. |
18 | 19 |
|
19 | 20 | Results
|
20 | 21 | -------
|
| 22 | +The size of the ITK image data read from the input file = itkSize2 ([221, 257]) |
21 | 23 |
|
22 |
| -NA |
| 24 | +The size of the NumPy array viewed from itk::Image = (257, 221) |
| 25 | +The size of the NumPy array copied from itk::Image = (257, 221) |
| 26 | +ITK image data size after convesion from NumPy = itkSize2 ([221, 257]) |
| 27 | + |
| 28 | +ITK image data pixel value at [2,1] = 6 |
| 29 | +NumPy array pixel value at [2,1] = 8 |
23 | 30 |
|
24 | 31 |
|
25 | 32 | Code
|
|
0 commit comments