[vtkusers] write vtkImageCast output to a raw volume data file.

Jianlong Zhou zhou at isg.cs.uni-magdeburg.de
Sun Jan 26 11:06:10 EST 2003


All,

I use vtkImageCast to convert a unsigned short format volume data to unsigned char format 
and want to export the cast result to a raw volume data file. Some of my codes is like 
followings. The problem is that after I get the converted raw data, the raw data size is not 
correct (my data is 512X512X160 and unsigned char, it should be 41943040 byte, but the 
result is 41948805 byte). Another problem is when I visualize this converted data, the result 
is not correct. It seems that some parts of all the silices moved to a direction a little. Would 
anyone tell me what the prolem is for my pipeline?

Thank you in advance,

Jianlong

//convert the unsigned short to unsigned char

vtkImageCast *cast =vtkImageCast::New();
cast->SetInput(reader->GetOutput());
cast->SetOutputScalarTypeToUnsignedChar();
cast->Update();

int extent[6];
int sizeOfData;
reader->GetDataExtent(extent);
sizeOfData=(extent[1]-extent[0]+1)*(extent[3]-extent[2]+1)*(extent[5]-extent[4]+1);

FILE *fp;
if((fp=fopen("converted.raw","w"))==NULL){
    return;
}

unsigned char *buffer;
buffer=(unsigned char*) (cast->GetOutput()->GetScalarPointer());
fwrite(buffer,sizeof(unsigned char),sizeOfData,fp);
fclose(fp);





More information about the vtkusers mailing list