Hi<br>


<br>


I am trying to read a 3D volume and write into a&nbsp; file. My code should
take any kind of pixel type and change it to specified type. I am
losing the data. Can any one tell me what is not working? here is my&nbsp;
code:<br>


<br>


#include &quot;itkImageFileReader.h&quot;<br>


#include &quot;itkImageFileWriter.h&quot;<br>


#include &quot;itkRescaleIntensityImageFilter.h&quot;<br>


<br>


int main(int argc, char *argv[])<br>


{<br>


&nbsp;&nbsp;&nbsp; //Check number of commandline parameters<br>


&nbsp;&nbsp;&nbsp; if( argc &lt; 3)<br>


&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std:: cerr &lt;&lt; &quot;Incorrect
number of parameters, check the usage: &quot; &lt;&lt; std::endl;<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std:: cerr &lt;&lt; &quot;inputFile&nbsp; outputFile &quot; &lt;&lt; std::endl;<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>


&nbsp;&nbsp;&nbsp; }<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>


&nbsp;&nbsp;&nbsp; //Input pixel type and output pixel type<br>


&nbsp;&nbsp;&nbsp; typedef unsigned short InputPixelType;&nbsp; //My data type is unsigned short<br>


&nbsp;&nbsp;&nbsp; typedef unsigned short OutputPixelType;<br>


<br>


&nbsp;&nbsp;&nbsp; //Dimension of the image<br>


&nbsp;&nbsp;&nbsp; const unsigned int Dimension = 3;<br>


<br>


&nbsp;&nbsp;&nbsp; const char* inputFilename&nbsp; = argv[1];<br>


&nbsp;&nbsp;&nbsp; const char* outputFilename = argv[2];<br>


<br>


&nbsp;&nbsp;&nbsp; typedef itk::Image&lt; InputPixelType, Dimension &gt; InputImageType;<br>


&nbsp;&nbsp;&nbsp; typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<br>


<br>


&nbsp;&nbsp;&nbsp; typedef itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br>


&nbsp;&nbsp;&nbsp; typedef itk::ImageFileWriter&lt; OutputImageType &gt; WriterType;<br>


<br>
&nbsp;&nbsp;&nbsp; typedef itk::RescaleIntensityImageFilter&lt;
InputImageType, OutputImageType &gt;&nbsp;&nbsp;&nbsp;
RescaleFilterType;<br>


<br>


&nbsp;&nbsp;&nbsp; RescaleFilterType::Pointer rescalefilter = RescaleFilterType::New();<br>


<br>


&nbsp;&nbsp;&nbsp; rescalefilter-&gt;SetOutputMinimum(&nbsp;&nbsp; 0 );<br>


&nbsp;&nbsp;&nbsp; rescalefilter-&gt;SetOutputMaximum( 2019 );<br>


<br>


&nbsp;&nbsp;&nbsp; //Create reader and writer, update the pipeline<br>


&nbsp;&nbsp;&nbsp; ReaderType::Pointer reader = ReaderType::New();<br>


&nbsp;&nbsp;&nbsp; WriterType::Pointer writer = WriterType::New();<br>


<br>


<br>


&nbsp;&nbsp;&nbsp; reader-&gt;SetFileName( inputFilename );<br>


&nbsp;&nbsp;&nbsp; writer-&gt;SetFileName( outputFilename );<br>


<br>


&nbsp;&nbsp;&nbsp; rescalefilter-&gt;SetInput( reader-&gt;GetOutput() );<br>


&nbsp;&nbsp;&nbsp;&nbsp; writer-&gt;SetInput( rescalefilter-&gt;GetOutput() );<br>


<br>


&nbsp;&nbsp;&nbsp; try<br>


&nbsp;&nbsp;&nbsp; {<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer-&gt;Update();<br>


&nbsp;&nbsp;&nbsp; }<br>


&nbsp;&nbsp;&nbsp; catch( itk::ExceptionObject &amp; err )<br>


&nbsp;&nbsp;&nbsp; {<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; err &lt;&lt; std::endl;<br>


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>


&nbsp;&nbsp;&nbsp; }<br>


<br>


&nbsp;&nbsp;&nbsp; return EXIT_SUCCESS;<br>


}<br>