<div>Hello,</div> <div> </div> <div>I have image of short pixel type. I need to save the image into another file with pixels of certain intensity levels. The code is given below but unfortunately it is saving pixels with intensity levels other than desired. Any idea would appreciated.</div> <div> </div> <div>Thanks<BR>Shahab</div> <div> </div> <div>#include "itkImage.h"<BR>#include "itkImageFileReader.h"<BR>#include "itkImageFileWriter.h"<BR>#include <iostream><BR>using namespace std;</div> <div> </div> <div>int main()<BR>{</div> <div>int xdim = 256;</div> <div>int ydim = 256;</div> <div>int zdim = 128;</div> <div><BR> typedef itk::Image< short, 3 > ImageType;<BR> ImageType::Pointer image = ImageType::New();</div> <div> </div> <div> typedef itk::ImageFileReader< ImageType > ReaderType;<BR> typedef itk::ImageFileWriter< ImageType > WriterType;</div> <div> </div>
<div> ReaderType::Pointer reader = ReaderType::New();<BR> WriterType::Pointer writer = WriterType::New();</div> <div> </div> <div> reader->SetFileName( "seg2.img" );<BR> writer->SetFileName( "rhippo_seg.hdr" );</div> <div> </div> <div> image = reader->GetOutput();<BR> writer->SetInput( reader->GetOutput() );</div> <div> </div> <div> try <BR> { <BR> reader->Update();<BR>} <BR> <BR> catch( itk::ExceptionObject & err ) <BR> { <BR> cout << "ExceptionObject caught !" << endl; <BR> cout << err << endl; <BR> system("pause");<BR> return 1;<BR>}<BR> <BR> ImageType::PixelType pixelValue;<BR> ImageType::IndexType pixelIndex;</div> <div> for(int z=0; z<zdim; z++){<BR> for(int y=0; y<ydim; y++){<BR> for(int x=0; x<xdim; x++){</div>
<div> pixelIndex[0] = x; // x position<BR> pixelIndex[1] = y; // y position<BR> pixelIndex[2] = z; // z position</div> <div> try <BR> { <BR> pixelValue = image->GetPixel( pixelIndex );<BR> if(pixelValue == 53) //need in this intensity value and hoping binary output image<BR> image->SetPixel( pixelIndex, 32767 );<BR> else<BR> image->SetPixel( pixelIndex, -32766 );<BR> } <BR> <BR> catch( itk::ExceptionObject & err ) <BR> { <BR> cout << "ExceptionObject caught !" << endl; <BR> cout << err << endl;
<BR> system("pause");<BR> return 1;<BR> }<BR> }<BR> }<BR> }<BR> <BR> try <BR> { <BR> writer->Update();<BR> } <BR> <BR> catch( itk::ExceptionObject & err ) <BR> { <BR> cout << "ExceptionObject caught !" << endl; <BR> cout << err << endl; <BR> system("pause");<BR> return 1;<BR> }<BR> <BR> system("pause");<BR> return 0;<BR>}</div><p>
                <hr size=1>Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. <a href="http://us.rd.yahoo.com/mail_us/taglines/postman7/*http://us.rd.yahoo.com/evt=39666/*http://beta.messenger.yahoo.com"> Great rates starting at 1¢/min.