← Back to team overview

dolfin team mailing list archive

Re: Image to Function data structure conversion

 

2009/1/29 Kent Andre <kent-and@xxxxxxxxx>:
> On to., 2009-01-29 at 14:03 +0000, A Navaei wrote:
>> 2009/1/29 Kent Andre <kent-and@xxxxxxxxx>:
>> > On ti., 2009-01-27 at 12:34 +0000, A Navaei wrote:
>> >> Kent: Luca is right about the lack of wrapping for double type. I was
>> >> not aware that you were using the debian package available in ubuntu,
>> >> that binary (which has been nicely packaged) is now a bit out of date
>> >> and uses an old design of wrapitk while only the types that Luca
>> >> mentioned are wrapped. If you have access to a fast server, compiling
>> >> wrapitk is not that bad, simply turn python wrapping and double type
>> >> supporting on in the cmake gui, and you're good to go. If you turn the
>> >> cpack debian option on, it will also automatically generate a ready to
>> >> use debian package.
>> >>
>> >
>> >
>> >
>> > So I have to used the svn version of both ITK and wrapitk ? Or can I
>> > download ITK 3.10 and compile with doubles. Anyway, I guess I the image
>> > pixels are of integer type and I don't need to convert these to
>> > doubles.
>>
>> itk 3.10 is buggy and some classes will not compile when wrapping,
>> please use the development version and follow the instructions in
>> http://code.google.com/p/wrapitk/ . (Note that when you compile itk,
>> only a small fraction of the library is actually compiled, the rest
>> are simply templates which need to be instantiated. wrapitk
>> instantiates and compiles every single class, and that's where the
>> buggs are discovered.)
>>
>> It doesn't matter if your input images are not of double type. Since
>> your output images must be of double type, in order to connect them to
>> dolfin, you must have double type wrapping on. If you want to use
>> numpy as a glue, you might be able to cast the interface numpy array
>> from int to double. Let me know if there are any problems.
>
>
> So I modified your code slightly to get it work using ubuntu packages,
> (I will go to the newer version  ... :) )
>
> from dolfin import *
> from numpy import *
> import itk
>
> dim = 2
> inType = itk.Image[itk.UC, dim]
>
> reader = itk.ImageFileReader[inType].New(FileName="bowling.jpg")
> reader.Update()
>
> itk_py_converter = itk.PyBuffer[inType]
> image_array = itk_py_converter.GetArrayFromImage( reader.GetOutput() )
>
>
> I have a 150x150 pixel images (in jpg) and running the above code  takes
> like 10 seconds ? What is wrong ?
>

Since I don't have the old version installed, I am unable to
re-produce the problem. itk to numpy is simply done by pointer
assignment (http://code.google.com/p/wrapitk/source/browse/trunk/ExternalProjects/PyBuffer/itkPyBuffer.txx#34),
there is no loop involved in this. (Of course I cannot speak for the
old version. Note that, that version uses another design which is
completely different to our new wrapping design).

I recommend jumping to the latest version. If you are not in a hurry
and compilation is a problem, you can use the debian package I'm going
to create sometime soon.


-Ali


Follow ups

References