<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>I am doing some image processing things.The process is read
image,select interested region of image,resample the interested region image
data,then write the data as </FONT><FONT size=3> MetaImage. But I don't
know how to write the MetaImage header .The program I writed as follows,I can
view the slice along z axis,but when I use the InsightSNAP to load the writed
image,the dimensions and spacing are wrong.Help me!</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>//</FONT></DIV>
<DIV><FONT size=2> //read
"E:/cochlea/DICOM/PA1/ST1/SE1"<BR> DicomReader->SetDirectoryName(filepath);<BR> DicomReader->SetDataSpacing(0.412109,0.412109,1.250000);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> int i,j,k;<BR> //vtkImageExport *exporter =
vtkImageExport::New();<BR> exporter->SetInput(DicomReader->GetOutput());<BR> exporter->ImageLowerLeftOn();//Lower
left<BR> // get info from exporter and create array to hold
data<BR> int memsize = exporter->GetDataMemorySize();<BR> int
*dimensions = exporter->GetDataDimensions();<BR> // export the data into
the array<BR> short *data = new
short[memsize/sizeof(short)];<BR> exporter->Export(data); </FONT></DIV><FONT
size=2>
<DIV><BR> </FONT><FONT size=2> // interested
region : 310-370,190-250,16-45<BR></FONT><FONT size=2> vtkImageData
*interestRegion=vtkImageData::New();<BR>
interestRegion->SetDimensions(61,61,30);//310-370,190-250,16-45<BR>
interestRegion->SetScalarTypeToShort();//<BR>
interestRegion->SetNumberOfScalarComponents(1);<BR>
interestRegion->AllocateScalars();<BR>
interestRegion->SetSpacing(0.412109,0.412109,1.25);<BR>
interestRegion->SetOrigin(0.0,0.0,0.0);<BR>
//310-370,190-250,16-45;61*61*30<BR> short *ptr
=(short*)interestRegion->GetScalarPointer();<BR>
for(i=0;i<30;i++)//z<BR> {<BR>
for(j=0;j<61;j++)//y<BR> {<BR>
for(k=0;k<61;k++)//x<BR> {<BR>
ptr[k + 61*(j + 61*i)]=data[k+310+dimensions[0]*(j+190 +
dimensions[1]*(i+16))];<BR> }<BR> }<BR>
}<BR>//sample<BR> imageResample->SetDimensionality(3);<BR>
imageResample->SetInput(interestRegion);<BR>
imageResample->SetAxisOutputSpacing(0,0.2);//spacing[3]<BR>
imageResample->SetAxisOutputSpacing(1,0.2);<BR>
imageResample->SetAxisOutputSpacing(2,0.2);<BR>
imageResample->SetInterpolationModeToLinear();<BR>
imageResample->SetOutputExtentToDefault();<BR>
imageResample->ReleaseDataFlagOff();<BR> <BR> vtkImageExport
*export = vtkImageExport::New();<BR>
export->SetInput(imageResample->GetOutput());<BR>
export->ImageLowerLeftOn();//Lower left<BR> // get info from
exporter and create array to hold data<BR> int memorysize =
export->GetDataMemorySize();<BR> int *Samdimensions =
export->GetDataDimensions();<BR> // export the data into the
array<BR> short *id = new short[memorysize/sizeof(short)];<BR>
export->Export(id); <BR> vtkImageImport *import =
vtkImageImport::New();<BR>
import->SetWholeExtent(1,Samdimensions[0],1,Samdimensions[1],1,Samdimensions[2]);<BR>
import->SetDataExtentToWholeExtent();<BR>
import->SetDataScalarTypeToShort();<BR>
import->SetImportVoidPointer(id);<BR> //write to MetaImage <BR>
metaImageWriter->SetFileDimensionality(3);<BR> metaImageWriter->SetInput(import->GetOutput());<BR>
metaImageWriter->SetFileName("Sampledimage.mhd");<BR> metaImageWriter->Write();
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> // view Z slice<BR>
viewer->SetInput(imageResample->GetOutput());//interestRegion<BR>
viewer->SetZSlice(120);</FONT></DIV>
<DIV><FONT size=2> viewer->SetColorWindow(2000);</FONT></DIV>
<DIV><FONT size=2> viewer->SetColorLevel(750);<BR>
viewer->Render(); </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2> delete [] data;<BR> delete [] id;<BR>
export->Delete();<BR> import->Delete();<BR> </FONT></DIV>
<DIV> </DIV></BODY></HTML>