<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Definitions of <span style="font-family:monospace,monospace">RescaleFilterType</span> and <span style="font-family:monospace,monospace">FilterType</span> should be like this:</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default" style=""><font face="monospace, monospace">typedef itk::RescaleIntensityImageFilter< InputImageType, OutputImageType > RescaleFilterType;</font></div><div class="gmail_default" style=""><font face="monospace, monospace">typedef itk::ExtractImageFilter< OutputImageType, OutputImageType > FilterType;</font></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 8, 2019 at 1:54 PM Shrabani Ghosh <<a href="mailto:srbn.ghosh99@gmail.com">srbn.ghosh99@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I did it like this and I am getting images like this now. <br>
<<a href="http://itk-insight-users.2283740.n2.nabble.com/file/t396636/slice1.png" rel="noreferrer" target="_blank">http://itk-insight-users.2283740.n2.nabble.com/file/t396636/slice1.png</a>> <br>
<br>
<br>
<br>
int main( int argc, char ** argv )<br>
{<br>
<br>
  //typedef signed short        InputPixelType;<br>
  /*typedef unsigned char       InputPixelType;<br>
  typedef unsigned char        OutputPixelType;*/<br>
  typedef signed short       InputPixelType;<br>
  typedef unsigned char      OutputPixelType;<br>
  typedef itk::Image< InputPixelType,  3 >    InputImageType;<br>
  typedef itk::Image< OutputPixelType, 2 >    OutputImageType;<br>
  typedef itk::ImageFileReader< InputImageType  >  ReaderType;<br>
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;<br>
  const char * inputFilename  = "G:/My Drive/BMES2019/New<br>
folder/subject1.nii";<br>
<br>
  {<br>
                int i = 1;<br>
<br>
                        std::string str="input//";<br>
                        std::string s1="slice";<br>
                        std::string s2 = std::to_string(i);<br>
                        std::string s3=".png";<br>
                        std::string s4=str+s1+s2+s3;<br>
                        const char *mycharp = s4.c_str();<br>
<br>
  const char * outputFilename = mycharp;<br>
<br>
  ReaderType::Pointer reader = ReaderType::New();<br>
  WriterType::Pointer writer = WriterType::New();<br>
<br>
  reader->SetFileName( inputFilename  );<br>
  writer->SetFileName( outputFilename );<br>
<br>
   typedef itk::RescaleIntensityImageFilter< InputImageType, InputImageType<br>
> RescaleFilterType;<br>
   RescaleFilterType::Pointer rescalefilter = RescaleFilterType::New();<br>
   rescalefilter->SetInput( reader->GetOutput() );<br>
<br>
  typedef itk::ExtractImageFilter< InputImageType,<br>
                                   OutputImageType > FilterType;<br>
  FilterType::Pointer filter = FilterType::New();<br>
  filter->InPlaceOn();<br>
  filter->SetDirectionCollapseToSubmatrix();<br>
   reader->UpdateOutputInformation();<br>
  InputImageType::RegionType inputRegion =<br>
           reader->GetOutput()->GetLargestPossibleRegion();<br>
<br>
  InputImageType::SizeType size = inputRegion.GetSize();<br>
  size[2] = 0;<br>
<br>
  InputImageType::IndexType start = inputRegion.GetIndex();<br>
  const unsigned int sliceNumber = stoi(s2);//atoi(argv[3]);<br>
  start[2] = sliceNumber;<br>
<br>
  InputImageType::RegionType desiredRegion;<br>
  desiredRegion.SetSize(  size  );<br>
  desiredRegion.SetIndex( start );<br>
<br>
  filter->SetExtractionRegion( desiredRegion );<br>
<br>
  filter->SetInput( rescalefilter->GetOutput() );<br>
  writer->SetInput( filter->GetOutput() );<br>
   try<br>
    {<br>
    writer->Update();<br>
    }<br>
  catch( itk::ExceptionObject & err )<br>
    {<br>
    std::cerr << "ExceptionObject caught !" << std::endl;<br>
    std::cerr << err << std::endl;<br>
        getchar();<br>
    return EXIT_FAILURE;<br>
    }<br>
    }<br>
  return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://itk-insight-users.2283740.n2.nabble.com/" rel="noreferrer" target="_blank">http://itk-insight-users.2283740.n2.nabble.com/</a><br>
The ITK community is transitioning from this mailing list to <a href="http://discourse.itk.org" rel="noreferrer" target="_blank">discourse.itk.org</a>. Please join us there!<br>
________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://itk.org/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">https://itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div>