[MINC-users] Quick way to flip data in a MINC file

Andrew Janke a.janke at gmail.com
Wed Sep 23 22:02:13 EDT 2015


Hi Alex,

The mincresample approach (with -nearest_neighbour) is what is used in
volgemodel for MDA's and works well, especially if you have other
transforms to concatenate in, but I was after something faster and
data based. Beware also that from a look at your chunk of code that I
think this will not do what you want if a volume has direction
cosines.

To get around this you could use minc_modify_header to set the starts
and direction cosines to identity, mincresample with your flip xfm and
then set the direction cosines and starts back to what they were.


a


On 23 September 2015 at 20:33, Alex Zijdenbos <zijdenbos at gmail.com> wrote:
> You are running through the volume 4 times, that does seem a bit excessive.
>
> I use mincresample for this with a flipping xfm, using the code snippet
> below. Draws on a perl lib that I can't (yet) share, but I'd be happy to
> provide the relevant subs (i.e., a working script) if anybody is
> interested. But the code below is probably understandable as-is. It
> supports flipping about the center-of-mass (com), start=0, or (what you are
> after) the volume center (center).
>
> -- A
>
> -----
>
> my %Dirs = ('xspace', 0, 'yspace', 1, 'zspace', 2);
>
> # Generate the flipping xfm
> my $Flip = &TmpFile('flip.xfm');
>
> my @Center = (0, 0, 0);
>
> if ($Center eq 'com') {
>     my @dimi = @Dirs{@Dir};
>     $Center[@dimi] = (&CoM($In))[@dimi];
> }
> elsif (($Center eq 'center') || ($Center eq 'start')) {
>     my $s = &Sampling($In);
>
>     foreach my $space (@Dir) {
>     my $dimi = $Dirs{$space};
>
>     die "Volume $In has no $space dimension?!\n" if (! $s->{n}[$dimi]);
>
>     $Center[$dimi] = ($Center eq 'start') ?
>         $s->{start}[$dimi] : $s->{start}[$dimi] + ($s->{n}[$dimi] - 1)/2.0
> * $s->{step}[$dimi];
>     }
> }
>
> my @Scales = (1, 1, 1);
>
> foreach my $space (@Dir) {
>     $Scales[$Dirs{$space}] = -1;
> }
>
> &Run(['param2xfm', '-clobber', '-scales', @Scales, '-center', @Center,
> $Flip]) && die;
>
> # Resample the input volume
> my @MR = ('mincresample', '-clobber', $Interpolation, '-transformation',
> $Flip);
> push(@MR, ($Center eq 'start') ? '-tfm_input_sampling' : ('-like', $In));
> &Run([@MR, $In, $Out]) && die;
>
>
> On Tue, Sep 22, 2015 at 10:56 PM, Andrew Janke <a.janke at gmail.com> wrote:
>
>> Hi all,
>>
>> Does anyone have any bright ideas/hackery of how to flip data (for a
>> dimension) in a MINC file? Here is what I currently do:
>>
>>    https://github.com/BIC-MNI/minc-widgets/blob/master/volflip/volflip#L84
>>
>> This takes about 2.5 minutes for a average sized volume (700x272x187).
>> This has been more than fine for a long time, but now I have a use
>> case that requires more speed.
>>
>> Failing this I'm going to have to resort to writing something in C/C++
>> or perhaps even use some HDF5 tool.
>>
>>
>>
>> a
>> _______________________________________________
>> MINC-users at bic.mni.mcgill.ca
>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>>
>>
> _______________________________________________
> MINC-users at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users


More information about the MINC-users mailing list