← Back to team overview

dolfin team mailing list archive

Re: Image to Function data structure conversion

 

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
>




Follow ups

References