C# Equivalent of GetArray(ViewFrom)Image

I am attempting to follow the SimpleITK2020 (Python) tutorial but with F#.

Part of the code in the “Accessing Pixels and Slicing” section is the following:

logo_copy[115:190, 0:height] = logo_copy[190:115:-1, 0:height]
plt.imshow(sitk.GetArrayViewFromImage(logo_copy))

What is the equivalent of:

  • GetArrayViewFromImage and GetArrayFromImage in C# and
  • the array slicing logo_copy[115:190, 0:height] = logo_copy[190:115:-1, 0:height] in C#?

For C# the following example shows how you can get a pointer to the image buffer and copy out the pixels:

https://simpleitk.readthedocs.io/en/master/link_CSharp_docs.html

I don’t think there’s any way of do the type of image slicing in C#.

There is no fancy syntax implemented for image slicing in C# but the filters which implement the operations are available:
https://simpleitk.org/doxygen/v2_0/html/classitk_1_1simple_1_1SliceImageFilter.html
https://simpleitk.org/doxygen/v2_3/html/classitk_1_1simple_1_1PasteImageFilter.html

Hello @general_rishkin,

With respect to the slicing flipping and pasting which is shown in that example, you will need to use the filters directly ExtractImageFilter, FlipImageFilter, and PasteImageFilter. Something along the lines of the following Python code:

extracted_sub_image = sitk.Extract(logo_copy, size=[75, height], index=[115, 0])
extracted_sub_image_flipped = sitk.Flip(extracted_sub_image, flipAxes=[True, False])
res = sitk.Paste(
    destinationImage=logo_copy,
    sourceImage=extracted_sub_image_flipped,
    sourceSize=extracted_sub_image_flipped.GetSize(),
    sourceIndex=[0] * extracted_sub_image_flipped.GetDimension(),
    destinationIndex=[115, 0],
)
1 Like