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

Alex Zijdenbos zijdenbos at gmail.com
Wed Sep 23 06:33:31 EDT 2015


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
>
>


More information about the MINC-users mailing list