[Insight-developers] SimpleITK - Image::GetPixel methods
Gaëtan Lehmann
gaetan.lehmann at jouy.inra.fr
Thu Apr 28 03:52:24 EDT 2011
Le 27 avr. 11 à 17:54, Bradley Lowekamp a écrit :
> Great!
>
> I'll give a shot at the __iter__ implementation as well.
>
> Do you think there are any other intrinsic python operators which
> should be implemented for SimpleITK, or have we covered most of them
> now?
>
there is the __len__ method which should return the number of pixels
in the image.
I can't think to anything else (for now ;-)).
> Brad
>
>
> On Apr 27, 2011, at 5:11 AM, Gaëtan Lehmann wrote:
>
>>
>> Le 27 avr. 11 à 03:41, Bradley Lowekamp a écrit :
>>
>>> Great!
>>>
>>> I know I was doing things not quite right there!
>>>
>>>
>>> On Apr 26, 2011, at 5:36 AM, Gaëtan Lehmann wrote:
>>>>
>>>>
>>>> It would be interesting to look at the GetPixel() performance -
>>>> if it is a lot slower than the specialized versions, then it may
>>>> be better to not hide the specialized versions, for the users who
>>>> wants to write faster code.
>>>
>>> Is your concern that the cost of all the if statements will be too
>>> great?
>>
>> Yes.
>> I'm not sure it will have much effect on performance, but it would
>> be nice to look at it.
>>
>> I've made a very simple timing test for WrapITK/Python when I moved
>> to a pure swig implementation, and it was quite informative:
>>
>> Wrapping/WrapITK/Languages/Python/Tests/timing.py
>>
>>> I have seen switch like statements implemented with dictionaries.
>>> This should reduce the switch statement from cost of N to logN or
>>> perhaps they are implemented with a hash... either way N is only
>>> 8, and it should be an interesting comparison.
>>
>> Yes, would be nice to compare.
>>
>>>
>>> The current implementation in sitkImage is that the correct set/
>>> get methods is required to be call or else and exception will be
>>> thrown. For strongly typed languages like C++ or Java this will be
>>> a pain, for for the implementation we have discussed here in
>>> python or other scripting languages, should be pretty easy to use.
>>>
>>
>> I think it should be possible to use overloaded methods to avoid
>> that pain with the Set methods.
>> For the Get method, I don't see what else could be done...
>>
>>>
>>> On another note, what do you think of implementing the iteration
>>> hidden function in python for the simpleITK Image?
>>
>> looks like a very good idea. There could be 2 versions:
>>
>> * the standard __iter__ would return only the pixel value
>> * another one which would also return the index
>>
>> Could be something like:
>>
>> def __iter__(self):
>> for idx, value in self.IterateWithIndex():
>> yield value
>>
>> def IterateWithIndex(self):
>> if self.GetDimension() == 2:
>> for x in range(self.GetWidth()):
>> for y in range(self.GetHeight()):
>> idx = (x, y)
>> value = self.GetPixel(*idx)
>> yield idx, value
>> elif self.GetDimension() == 3:
>> for x in range(self.GetWidth()):
>> for y in range(self.GetHeight()):
>> for z in range(self.GetDepth()):
>> idx = (x, y, z)
>> value = self.GetPixel(*idx)
>> yield idx, value
>>
>>
>> that can be used that way
>>
>> # compute the mean pixel value in the image
>> mean = sum(img) / len(img)
>>
>> or
>>
>> # compute the square value pixel wise
>> for idx, value in img.IterateWithIndex():
>> img[idx] = value**2
>>
>> Gaëtan
>>
>>
>>>
>>> Brad
>>>
>>>>
>>>> Gaëtan
>>>>
>>>>
>>>>
>>>>
>>>> Le 22 avr. 11 à 22:25, Bradley Lowekamp a écrit :
>>>>
>>>>> Gaetan,
>>>>>
>>>>> You have provided valuable feedback with several other python
>>>>> related issues and was looking for comments on the current.
>>>>>
>>>>> Despite it sounding easy, implementing the sitk::Image::GetPixel
>>>>> method is rather challenging due to the numerous types of images
>>>>> underneath. I have a branch in my SimpleITK github, which will
>>>>> add this much needed feature.
>>>>>
>>>>> The sitk::Image class will be customized for each language to
>>>>> provide a natural interface. This is what I have done for python:
>>>>>
>>>>> https://github.com/blowekamp/SimpleITK/commit/b821617f013ee18c7cc2ae727eec3d20ad2b5875
>>>>>
>>>>> I realize now it needs some comments....
>>>>>
>>>>> It is not clear to me if the index argument should be multiple
>>>>> arguments or an array, or both. As arguments are not strongly
>>>>> typed, I am not certain of how to do methods overloading, based
>>>>> on the arguments. In another methods I used isinstance(), but
>>>>> some frown about that. Do you have a suggestion on how I should
>>>>> overload methods in python? What do you think of this current
>>>>> interface?
>>>>>
>>>>> Brad
>>>>>
>>>>> ========================================================
>>>>> Bradley Lowekamp
>>>>> Lockheed Martin Contractor for
>>>>> Office of High Performance Computing and Communications
>>>>> National Library of Medicine
>>>>> blowekamp at mail.nih.gov
>>>>>
>>>>>
>>>>
>>>> --
>>>> Gaëtan Lehmann
>>>> Biologie du Développement et de la Reproduction
>>>> INRA de Jouy-en-Josas (France)
>>>> tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
>>>> http://voxel.jouy.inra.fr http://www.itk.org
>>>> http://www.mandriva.org http://www.bepo.fr
>>>>
>>>
>>
>> --
>> Gaëtan Lehmann
>> Biologie du Développement et de la Reproduction
>> INRA de Jouy-en-Josas (France)
>> tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
>> http://voxel.jouy.inra.fr http://www.itk.org
>> http://www.mandriva.org http://www.bepo.fr
>>
>
> ========================================================
> Bradley Lowekamp
> Lockheed Martin Contractor for
> Office of High Performance Computing and Communications
> National Library of Medicine
> blowekamp at mail.nih.gov
>
>
--
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
http://voxel.jouy.inra.fr http://www.itk.org
http://www.mandriva.org http://www.bepo.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110428/09e787da/attachment.pgp>
More information about the Insight-developers
mailing list