Thanks very much Dennis. I wonder if you can give further directions.
Flip is a simple operation, but if the image is moved or rotate, there
is a problem: Say, move the image right 2 mm. In this case, the 2mm of
the right side of the image should be cut and the left side of the
image should be filled with probably background values. Can you show a
example how to do this example?
best
Xiang
On Thu, Jun 11, 2009 at 1:38 PM, Dennis Thompson<[log in to unmask]> wrote:
> An img file is just an un-wraped matrix.
>
> To flip the element with out changing the headers is simple in matlab.
>
> Something like this will work.
>
> % str1 = string for the file name to the .hdr file
> % str2 = strinf for the file name to the .img file
>
> [hdr, endian] = spm_read_hdr(str1);
>
> % set the big little endian case
> if isnan(endian), endian = 'l';
> elseif endian, endian = 'b';
> else endian = 'l'; end;
>
> % set the matrix dimensions
> X = hdr.dime.dim(2);
> Y = hdr.dime.dim(3);
> Z = hdr.dime.dim(4);
>
> datatype = hdr.dime.datatype;
> switch datatype
> case 2
> datatype = '*uint8';
> case 4
> datatype = '*int16';
> case 16
> datatype = '*single';
> case 32
> datatype = '*float';
> case 64
> datatype = '*double';
> otherwise datatype = '*double';
> end
> fid = fopen(str2,'r',endian);
>
> imag = fread(fid,X*Y*Z,datatype);
>
> fclose(fid)
>
> % convert vector into 3D matrix
> imag = reshape(imag,X,Y,Z);
>
> % to flip in X direction
> imag = imag(X:-1:1,:,:)
>
>
> fid = fopen(str2,'w');
> fwrite(fid,image(:),datatype);
> fclose(fid)
>
>
>
>
>
>
>
>
> On Thu, Jun 11, 2009 at 11:15 AM, Xiang Wu<[log in to unmask]> wrote:
>> Hi all
>> We want to reorient the spm5 beta file, say beta_0001.hdr (img). And we want
>> to apply the reorientation on the actual image but not the head file.
>> However, spm seems only change the head file, because when we replace the
>> reoriented .hdr file with the the original .hdr file, the image looks
>> without orientation. Can somebody tell us how to apply reorientation on .img
>> file?
>>
>> Thanks
>> xiang
>>
>
|