[Rtk-users] using rtk in matlab : input images for filters from matlab data types

Simon Rit simon.rit at creatis.insa-lyon.fr
Fri Mar 24 05:32:10 EDT 2017


Hi,
SimpleRTK is compiled in single precision and Matlab uses double
precision by default. So you need to do
volume = py.SimpleRTK.GetImageFromArray(result.astype(py.numpy.float32));

A few remarks on your program:
- there is a transpose that I renamed to cube,
- you create volume_meta just to copy information from it, I think you
can directly set information to volume,
- there is a typo at the end, volume should be used instead of img.

Your modified example is attached.
Simon

On Fri, Mar 24, 2017 at 9:16 AM, Julia Semyakishkina
<prekrasnaya1985 at gmail.com> wrote:
> thanks for the fast reply.
>
> Oops, it seems i missed that there is a backward operation of
> GetArrayFromImage, i.e. GetImageFromArray..
> However, forward still doesn't work for me.
> This example code
>
> % geometry
> g = py.SimpleRTK.ThreeDCircularProjectionGeometry();
> for i=0:359,
>     g.AddProjection(500,1000,i);
> end
>
> % what projects
> cube1 = zeros(128,128,128);
> cube = single(cube1);
>
> cube(17:112,17:112,17:112) = 1;
> cube(33:96,33:96,33:96) = 0;
>
> data_size = size(cube);
> result = py.numpy.reshape(cube(:)', int32(fliplr(size(transpose))));
> volume = py.SimpleRTK.GetImageFromArray(result);
>
> const = py.SimpleRTK.ConstantImageSource();
> const.SetSpacing(py.list([1,1,1]));
> const.SetSize(py.list(int32(data_size)));
> const.SetOrigin(py.list([-64.5,-64.5,-64.5]));
> volume_meta = const.Execute();
>
> volume.CopyInformation(volume_meta);
>
> % projections
>
> const2 = py.SimpleRTK.ConstantImageSource();
> const2.SetSpacing(py.list([1,1,1]));
> const2.SetSize(py.list(int32([512,1,360])));
> const2.SetOrigin(py.list([-255.5,0,0]));
> proj = const2.Execute();
>
> % forward
>
> forward = py.SimpleRTK.JosephForwardProjectionImageFilter();
> forward.SetGeometry(g);
> proj = forward.Execute(proj, img);
>
> caused the following error :
> Error using SimpleRTK>Execute (line 6218)
> Python Error: RuntimeError: Exception thrown in SimpleRTK
> JosephForwardProjectionImageFilter_Execute:
> $RTK_BUILD$/SimpleRTK-build/Code/BasicFilters/src/srtkJosephForwardProjectionImageFilter.cxx:100:
> srtk::ERROR: Image2 for JosephForwardProjectionImageFilter doesnt match type
> or dimension!
>
> I tried different types of cube, but with no success.
>
>
> On Thu, Mar 23, 2017 at 11:01 PM, Simon Rit <simon.rit at creatis.insa-lyon.fr>
> wrote:
>>
>> Hi Julia,
>> I would have used
>> volume = py.GetImageFromArray(result)
>> instead of your last line. Does this work? If it does, then you have
>> to be sure that you set correctly the origin, spacing and direction
>> (the ITK meta information). One way to do this if you already have an
>> image with the correct meta information would be to use
>> py.volume.CopyInformation(volume)
>> Simon
>>
>> On Thu, Mar 23, 2017 at 11:14 AM, Julia Semyakishkina
>> <prekrasnaya1985 at gmail.com> wrote:
>> > Hello.
>> > In matlab example from http://wiki.openrtk.org/index.php/SimpleRTK
>> > volume
>> > which is projected generates in SheppLoganPhantomFilter(). But i have my
>> > own
>> > volume, that is stored in matlab regular matrix for example.
>> >
>> > What i want to do:
>> > forward = py.JosephForwardProjectionImageFilter();
>> > forward.SetGeometry(g);
>> > projs = forward.Execute(projs, volume);
>> >
>> > The problem is to initialize the volume parameter.
>> > By this code
>> > data_size = size(matimg);
>> > transpose = matimg';
>> > result=py.numpy.reshape(transpose(:)', int32(data_size));
>> > volume = py.Image.fromarray(result);
>> >
>> > i store volume in type of py.Image, but in Execute() method i have to
>> > pass
>> > py.SimpleRTK.SimpleRTK.Image type. So, is there way to do such
>> > convertation
>> > ? Or is there some another way to init py.SimpleRTK.SimpleRTK.Image with
>> > my
>> > own matlab data ?
>> >
>> >
>> >
>> > _______________________________________________
>> > Rtk-users mailing list
>> > Rtk-users at public.kitware.com
>> > http://public.kitware.com/mailman/listinfo/rtk-users
>> >
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.m
Type: application/octet-stream
Size: 836 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/rtk-users/attachments/20170324/73fd75d9/attachment-0001.obj>


More information about the Rtk-users mailing list