[Insight-users] Urgent!!Writing image
Selim Hasan
selimhasan at gmail.com
Mon May 11 12:27:18 EDT 2009
Hi all,
I wrote a code to read float numbers from a file and tried to create a 3-D
.vtk image.
I have an image in the end but the image is proper?
Can some one help to solve this problem??
I attached my code!!!!
The input file has float numbers, I want to read from the file and write the
pixel value.
****************************************************************************************************
void Ui_MainWindow::makeimage()
{
cout<<"MakeImage"<<endl;
FILE *fp;
FILE *fpp;
float f;
fp = fopen("C:\\selimmingwinput\\FA.txt", "r");
fpp = fopen("C:\\selimmingwinput\\b0.txt", "r");
if (fp == NULL)
{
printf("I couldn't open results.dat for reading.\n");
exit(0);
}
int counter =0;
// ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
typedef itk::Image< float, 3 > ImageType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ImageType::Pointer image = ImageType::New();
WriterType::Pointer writer = WriterType::New();
cout<<"MakeImage"<<endl;
ImageType::IndexType start;
ImageType::SizeType size;
size[0] = 144; // size along X
size[1] = 144; // size along Y
size[2] = 60; // size along Z
start[0] = 0; // first index on X
start[1] = 0; // first index on Y
start[2] = 0; // first index on Z
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
image->SetRegions( region );
image->Allocate();
ImageType::PixelType initialValue = 0;
image->FillBuffer( initialValue );
cout<<"MakeImage"<<endl;
ImageType::PixelType pixelValue;
ImageType::IndexType pixelIndex;
ImageType::SpacingType spacing;
spacing[0]=0.33;
spacing[1]=0.33;
spacing[2]=1.2;
int counter2=0;
ImageType::PointType origin;
origin[0]=0.0;
origin[1]=0.0;
origin[2]=0.0;
image->SetOrigin(origin);
image->SetSpacing(spacing);
for(int z=0;z<144;z++)
{
for(int j=0;j<144;j++)
{
for(int i=0;i<60;i++)
{
pixelIndex[0] = j; // x position
pixelIndex[1] = z; // y position
pixelIndex[2] = i; // z position
fscanf (fp, "%f", &f);
pixelValue=f;
// cout<<pixelValue<<endl;
image->SetPixel( pixelIndex, pixelValue );
counter++;
}
}
}
cout<<counter<<endl;
cout<<"MakeImage"<<endl;
writer->SetInput(image);
writer->SetFileName("C:\\selimmingwinput\\test.vtk");
cout<<"MakeImage"<<endl;
try
{
writer->Update();
}
catch( itk::ExceptionObject & e )
{
std::cerr << "WRITER UPDATE ERROR" << std::endl;
std::cerr << e << std::endl;
}
}
***************************************************************************************************
--
Selim Hasan
Yeditepe University
Computer Science Engineering
selimhasan at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090511/6669ae7a/attachment.htm>
More information about the Insight-users
mailing list