cnkhanh
(Chau Ngan Khanh)
September 20, 2022, 4:50am
1
I tried to write something like the below using python, I can’t find equivalence classes in python.
Is there any way to do it in python?
typedef itk::ImageRegionIterator< OutputImageType > OutIteratorType;
IteratorType fixedImageI( fixedImage, fixedImageRegion );
typedef itk::ImageRegionIterator< OutputImageType > OutIteratorType;
OutIteratorType sAirTrappingI(sAirTrapping,fixedImageRegion);
dzenanz
(Dženan Zukić)
September 20, 2022, 11:53am
2
There are no iterators in Python. Pixel iteration is quite inefficient in Python. The closest equivalent is using value = image.GetPixel(index)
and image.SetPixel(index, value)
.
1 Like
cnkhanh
(Chau Ngan Khanh)
September 21, 2022, 4:04am
3
Could you please give me an example about the equivalent of the below in Python? I am a newbie in this field, I do not understand it clearly
RegionType fixedImageRegion=fixedImage->GetBufferedRegion();
IteratorType fixedImageI( fixedImage, fixedImageRegion );
....
++fixedImageI
dzenanz
(Dženan Zukić)
September 21, 2022, 12:03pm
4
Take a look at this example , it has both C++ and Python code.
dzenanz
(Dženan Zukić)
September 21, 2022, 12:05pm
5
If you want to iterate over the entire image, the nested for loops is the usual approach in Python:
for k in range (0, zSize):
for j in range (0, ySize):
for i in range (0, xSize):
image.SetPixel(...)
1 Like