<div>Hi,</div><div>i'm working with ITK and my purpose is to segment a gradient 3D image of a CT volume in the best way possible. I have to use smoothed PET volumes in order to increase precision in segmenting the gradient image. My idea is to modify the gradient image voxel per voxel in particular those voxels that can make more sharp the edges. I wrote a code that accesses to voxels and modifies them. The problem is that a volume is made by a set of slice and i can't modify simply the voxel but i must look also to changing slices. </div>
<div>The code is here:</div><div><br></div><div>#include "itkImage.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageToVTKImageFilter.h"</div>
<div>#include "vtkImageViewer.h"</div><div><br></div><div>int main( int argc, char * argv[] )</div><div>{</div><div> // Verify the number of parameters in the command line</div><div> if( argc < 3 )</div><div>
{</div><div> std::cerr << "Usage: " << std::endl;</div><div> std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;</div><div> return EXIT_FAILURE;</div>
<div> }</div><div><br></div><div> typedef short PixelType;</div><div> const unsigned int Dimension = 3;</div><div> typedef itk::Image< PixelType, Dimension > ImageType;</div><div><br></div><div>
typedef itk::ImageFileReader< ImageType > ReaderType;</div><div> typedef itk::ImageFileWriter< ImageType > WriterType;</div><div> </div><div> ReaderType::Pointer reader = ReaderType::New();</div><div> WriterType::Pointer writer = WriterType::New();</div>
<div> </div><div><br></div><div> // Here we recover the file names from the command line arguments</div><div> //</div><div> const char * inputFilename = argv[1];</div><div> const char * outputFilename = argv[2];</div>
<div><br></div><div> reader->SetFileName( inputFilename );</div><div><br></div><div><br></div><div>///</div><div>ImageType::Pointer image = reader->GetOutput();</div><div><br></div><div><br></div><div> ImageType::IndexType start;</div>
<div> ImageType::SizeType size;</div><div><br></div><div> size[0] = 100; // size along X</div><div> size[1] = 100; // size along Y</div><div> size[2] = 100; // size along Z</div><div><br></div><div> start[0] = 109; // first index on X</div>
<div> start[1] = 190; // first index on Y</div><div> start[2] = 177; // first index on Z</div><div><br></div><div> ImageType::RegionType region;</div><div> region.SetSize( size );</div><div> region.SetIndex( start );</div>
<div> </div><div> // Pixel data is allocated</div><div> image->SetRegions( region );</div><div> image->Allocate();</div><div><br></div><div> ImageType::PixelType initialValue = 0;</div><div> image->FillBuffer( initialValue );</div>
<div><br></div><div> reader->Update();</div><div><br></div><div>image->DisconnectPipeline();</div><div><br></div><div> ImageType::IndexType pixelIndex;</div><div> </div><div> int i,j,k;</div><div> for(i=103;i<203;i++)</div>
<div> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for(j=282;j<382;j++)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for(k=186;k<286;k++)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>pixelIndex[0] = i; // x position</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>pixelIndex[1] = j; // y position</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>pixelIndex[2] = k; // z position</div><div><br></div><div>//<span class="Apple-tab-span" style="white-space:pre">                        </span>ImageType::PixelType pixelValue = image->GetPixel( pixelIndex );</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>image->SetPixel( pixelIndex, 256 );</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div> }</div><div><br></div><div>///</div><div><br></div><div> writer->SetFileName( outputFilename );</div><div> writer->SetInput( image );</div>
<div><br></div><div> try </div><div> { </div><div> writer->Update(); </div><div> } </div><div> catch( itk::ExceptionObject & err ) </div><div> { </div><div> std::cerr << "ExceptionObject caught !" << std::endl; </div>
<div> std::cerr << err << std::endl; </div><div> return EXIT_FAILURE;</div><div> } </div><div>}</div><div><br></div><div><br></div><div>this code is only an example: it draws a 3D rectangle in the image. Imagine you want to modify the edges around liver. I'm not able to modify the desidered voxels using this code.</div>
<div>Does anyone know how to simply access to the voxels in order to modify them?</div><div>Please give an idea, also a raw idea...thanks so much.</div><div>Bye, </div><div>Marco</div>