[Insight-users] SetPixel value.

Luis Ibanez luis.ibanez at kitware.com
Fri Oct 31 12:58:01 EDT 2008


Hi Javier,


You should not manually change the content of an image
that is produced as the output of a filter (or a reader).

You shouldn't either try to manually allocate memory
for an image that is the output of a reader.

---

You should decide if you want to create the images from
scratch or whether you want to read an image from disk,
disconnect it from the reader, and then proceed to modify
its pixel values.



You may want to try something like:

  ImageType::Pointer newimage = reader->GetOutput();

  newimage->DisconnectPipeline();

  ImageType::IndexType pixelLocation1;
  pixelLocation[0] = 80;
  pixelLocation[1] = 80;

  PixelType pixelValue = 0;

  newiamge->SetPixel( pixelLocation1, pixelValue );

  writer->SetInput( newimage );
  writer->SetFileName( "outputImage.mhd" );
  writer->Update();



  Regards,


      Luis


-------------------------------------------
Javier González González-Zabaleta wrote:
> Hi,
> 
> my name's Javier González and I'm working with ITK, VTK y MFC on C++ for 
> 7 months. I'm trying to make changes in a 2D image to make a graph. I 
> only need put some point and maybe some lines. I'm using 
> SetPixel(...,...) but when I show my image It has not changed. ¿May I 
> use another method? My code is:
> 
> ------------------------------------------------------------------------------------------------------------------------------------------
> const char * inputFilename  = "D:/fondografica.jpg";
> reader = ReaderType::New();
> reader->SetFileName( inputFilename );
> ImageType::Pointer newimage = reader->GetOutput();
> ImageType::SizeType size;
>     size[0] = 255; // size along X
>     size[1] = 255; // size along Y
> ImageType::IndexType start;
>     start[0] = 0; // first index on X
>     start[1] = 0; // first index on Y
> ImageType::RegionType region;
>     region.SetSize( size );
>     region.SetIndex( start );
> newimage->SetRegions(size);
> newimage->Allocate();
>    
> ImageType::Pointer image = this->pitkDICOM5->GetOutput();
> ImageType::IndexType pixelValue1;
>     pixelValue1[0] = 80;
>     pixelValue1[1] = 80;
> image = this->pitkDICOM4->GetOutput();
> ImageType::IndexType pixelValue2;
>     pixelValue2[0] = 125;
>     pixelValue2[1] = 125;
> image = this->pitkDICOM3->GetOutput();
> ImageType::IndexType pixelValue3;
>     pixelValue3[0] = 170;
>     pixelValue3[1] = 170;
> image = this->pitkDICOM1->GetOutput();
> ImageType::IndexType pixelValue4;
>     pixelValue4[0] = 215;
>     pixelValue4[1] = 215;
> 
>     newimage->SetPixel(pixelValue1, 0);
>     newimage->SetPixel(pixelValue2, 0);
>     newimage->SetPixel(pixelValue3, 0);
>     newimage->SetPixel(pixelValue4, 0);
> 
>     return newimage;
> ------------------------------------------------------------------------------------------------------------------------------------------
> 
> Thans for your help.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list