← Back to team overview

dolfin team mailing list archive

Re: Image to Function data structure conversion

 

Hey Kent,
 I'm following the thread, good stuff!
I suppose you're using Paul Novotny's binaries. In that case, only the
following pixel types are explicitly instantiated by the Python wrappers
(see http://paulnovo.org/node/3)

• unsigned char
• unsigned short
• RGB unsigned short
• float
• complex float
• vector float
• covariant vector float

In your case, *I suppose* that what happens is that D2 (doubles in 2D) are not
available as pixel types.
This means that you'd want to use F2 as the image type, rather than D2.
In case you need doubles, either recompile ITK and WrapITK or complain
with Paul :-)
However, I admit I don't normally use WrapITK, so the suggestion might be bogus.

Keep up the good work. There are several potential interesting developments
that could stem from this work...

Luca


On Jan 27, 2009, at 9:22 AM, kent-and@xxxxxxxxx wrote:


Does this code require a particular version ? I get:

~/tmp >python image_read.py
[kent-and-laptop:08136] mca: base: component_find: unable to open osc
pt2pt: file not found (ignored)
Traceback (most recent call last):
 File "image_read.py", line 8, in <module>
   reader = itk.ImageFileReader[inType].New(FileName="bowling.jpg")
File "/usr/lib/WrapITK/Python/itkTemplate.py", line 215, in __getitem__
   raise KeyError, 'itkTemplate : No template %s for the %s class' %
(str(parameters), self.__name__)
KeyError: "itkTemplate : No template [<class 'itkImage.itkImageD2'>] for
the itk::ImageFileRead


Kent



I agree with Anders.

The dof_map does of course have a very simple structure in this case,
which
can be written as an explicit formula. This is an advantage we usually
don't
have when working on unstructured meshes. Still, I think the cpu time and
memory
will not be dominated by the dof_map so it might be smart to wait about
taking
advantage of this until after profiling.

Can you store the images eg as a numpy array?

Do you want to perform the profiling with numpy as a bridge between
itk and dolfin? There is an external project in wrapitk called
PyBuffer which generates the numpy interface. You must have wrappring
for double type on. I don't have access to python itk binaries right
now, but I guess the following untested script should allow you to
start such profiling. This is written for 2D images and generalisation
to nD is trivial.


-Ali


-------------------------------
from dolfin import *
from numpy import *
import itk

dim = 2
inType = itk.Image[itk.D, dim]

reader = itk.ImageFileReader[inType].New(FileName="/path/to/ file.bmp")
reader.Update()

itk2numpy = itkPyBufferD2_New()
numpy_arr = itk2numpy.GetArrayFromImage( reader.GetOutput() )
shape = numpy_arr.shape

mesh = UnitSquare(shape[0]-1, shape[1]-1)

class ImageFunction(Function):
   def eval(self, value, x):
       i = int((self.A.shape[0]-1)*x[0])
       j = int((self.A.shape[1]-1)*x[1])
       print i,j
       value[0] = self.A[(i,j)]

V = FunctionSpace(mesh, "CG", 1)
f = ImageFunction(V)
f.A = numpy_arr

plot(f) # can viper plot 2d images better than this?
interactive()
--------------------------------
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev



_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev

--
Luca Antiga, PhD
Head, Medical Imaging Unit,
Biomedical Engineering Department,
Mario Negri Institute.
mail: Villa Camozzi, 24020, Ranica (BG), Italy
phone: +39 035 4535-381
email: antiga@xxxxxxxxxxxxx
web: http://villacamozzi.marionegri.it/~luca


References