SPM99 Gem 2: Zeroing NaN values

In addition to setting NaN values to zero, this gem is also useful as a basic skeleton for reading each slice, doing something to it, and then writing it out.

Subject: Re: NaN values in beta values
From: John Ashburner 
Date: Mon, 23 Oct 2000 17:27:24 +0100 (BST)
To: spm@mailbase.ac.uk, steffejr@umdnj.edu

I can't think of any nice way of doing this with ImCalc, so I'm afraid
I'll have to show you a more labour intensive method that should be
modified slightly (as the filenames need changing) before pasting into
Matlab.

	VI       = spm_vol('original_beta.img');
	VO       = VI;
	VO.fname = 'patched_beta.img';
	VO       = spm_create_image(VO);
	for i=1:VI.dim(3),
		img      = spm_slice_vol(VI,spm_matrix([0 0 i]),VI.dim(1:2),0);
		tmp      = find(isnan(img));
		img(tmp) = 0;
		VO       = spm_write_plane(VO,img,i);
	end;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s