[Insight-users] Urgent!!Writing image
Luis Ibanez
luis.ibanez at kitware.com
Wed May 20 23:53:07 EDT 2009
Hi Selim,
Your code look ok.
What exactly is the problem that you are observing ?
What do you mean when you say that
"the image is proper" ?
What are you using for visualizing the output image ?
Regards,
Luis
--------------------
Selim Hasan wrote:
> 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 <mailto:selimhasan at gmail.com>
>
>
> ------------------------------------------------------------------------
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list