[Insight-users] In / out

Luis Ibanez luis.ibanez at kitware.com
Mon Sep 12 08:42:40 EDT 2005



Hi Daniel,


Thanks for making the trials and sending us the images and your code.

 From your code it seems that you are not setting the thresholding
filter quite right. You have now:


      typedef itk::ThresholdImageFilter< ImageType >  FilterType;
      FilterType::Pointer filter = FilterType::New();
      filter->SetInput( importer->GetOutput() );

      filter->ThresholdAbove( 180 );
      filter->Update();
      filter->ThresholdBelow( 180 );
      filter->Update();
      filter->ThresholdOutside( 170,190 );
      filter->Update();
      writer2->SetInput( filter->GetOutput() );
      writer2->Update();


You are calling ThresholdAbove(), ThresholdBelow() and
ThresholdOutised() in the same use of the filter.

In practice you should call only one of these methods.


You are also missing to define the OutsideValue(), which defaults
to the Zero trait of the PixelType.


What this filter does is to preserve all the intensitiy values of
pixels that fall inside the range of the LowerThreshold and
UpperThreshold, while setting all other pixels to the "OutsideValue",


It would seem that the filter that you really want is the
BinaryThresholdImageFilter, in which you provide a single threshold
in order to obtain a binary image.  Note that the BinaryThreshold
ImageFilter allows you to provide values for "outside" and "inside".



Please refer to the ITK Software Guide

              http://www.itk.org/ItkSoftwareGuide.pdf

for instructions on the use of each one of these thresholding
filters.  You will find them in Sections

      6.1.1  "Binary Thresholding"   pdf-page 172
      6.1.2  "General Thresholding"  pdf-page 167



   Regards,


      Luis




-------------------------
Einstein, Daniel R wrote:
> Hi Luis,
> 
> OK. Having gotten past the difficulty with the libraries, I was finally able to generate the .mhd files to compare before and after. As per your suggestion, file1 contains the dump from the importer, and file2 contains the dump from the threshold filter. I looked at both in paraview (which is interesting but wants to see everything as a mesh - I will get around to building FLTK for ImageView) and basically they are the same. The files are attached. Also, attached is the modified function for the sake of completeness. The relevant function is about halfway down and is called 
> 
> void ThreeDFilters::helloWorldFilter(float *fdata, int xdim, int ydim, int zdim,
>                                       int numiter, QApplication *app) 
> 
> It does look like something is getting lost along the way, but why I don't know.
> 
> Best Regards,
> Dan
> 
>   
> 
> 
> Daniel R Einstein, PhD
> Biological Monitoring and Modeling
> Pacific Northwest National Laboratory
> P.O. Box 999; MSIN P7-59
> Richland, WA 99352
> Tel: 509/ 376-2924
> Fax: 509/376-9064
> daniel.einstein at pnl.gov
> 
> 
> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
> Sent: Sunday, August 28, 2005 9:43 AM
> To: Einstein, Daniel R
> Cc: insight-users at itk.org
> Subject: Re: [Insight-users] In / out
> 
> 
> 
> Hi Daniel,
> 
> Your code looks good,
> 
> In order to identify whether the problem is in the transfer of data from your app to ITK, or from ITK to your app, please add two writers, one that writes your image as it is received at the Import filter, and another one that writes it as it is produced at the output of the Thresholding filter.
> 
> 
> The code will be like:
> 
>    typedef itk::ImageFileWriter< ImageType > WriterType;
> 
>    WriterType::Pointer writer1 = WriterType::New();
>    WriterType::Pointer writer2 = WriterType::New();
> 
>    writer1->SetFileName("file1.mhd");
>    writer2->SetFileName("file2.mhd");
> 
>    writer1->SetInput( importer->GetOutput() );
>    writer2->SetInput( file->GetOutput() );
> 
> Then, add a writer1 update after you update the importer,
> 
>    importer->Update();
>    writer1->Update();
> 
> and a writer2 update after you update the thresholding filter.
> 
>    file->Update();
>    writer2->Update();
> 
> 
> 
> You can look at the resulting images with the ImageViewer available in InsightApplications, or with ParaView that can be downloaded for free from www.paraview.org.
> 
> 
> 
> By writing these two images, we will know if data is getting lost along the way.
> 
> 
> 
> Please let us know what you find.
> 
> 
>     Thanks
> 
> 
>        Luis
> 
> 
> --------------------
> Einstein, Daniel R wrote:
> 
>>Hello,
>>
>>Terribly sorry. I have read the UG and looked over the tutorials 
>>concerning reading and writing to a buffer. My code compiles and runs ....
>>but does nothing. To troubleshoot, I have implemented as fast and 
>>naïve threshold filter. Could someone please look this over and tell 
>>me what I am doing wrong?
>>
>>Regards,
>>Dan
>>
>>void myfunction::helloWorldFilter(float *fdata, int xdim, int ydim, 
>>int zdim,
>>                                      int numiter, QApplication *app) 
>>{
>>
>>//
>>// ***********************************************************************
>>//          Preliminaries to read the array into an ITK Image class *
>>// 
>>**********************************************************************
>>*
>>//
>>  typedef float PixelType;
>>  const unsigned int Dimension = 3;
>>  typedef itk::Image< PixelType, Dimension > ImageType;
>>  typedef itk::ImportImageFilter< PixelType, Dimension >   
>>ImportFilterType;  
>>  ImportFilterType::Pointer importer = ImportFilterType::New();       
>> 
>>  ImportFilterType::SizeType  size;
>>  size[0]  = xdim;  // size along X
>>  size[1]  = ydim;  // size along Y
>>  size[2]  = zdim;  // size along Z
>>
>>  ImportFilterType::IndexType start;
>>  start[0]=0;
>>  start[1]=0;
>>  start[2]=0;
>>
>>  ImportFilterType::RegionType region;
>>  region.SetIndex( start );
>>  region.SetSize(  size  );
>>  importer->SetRegion( region );
>> 
>>  double origin[ Dimension ];
>>  origin[0] = 0.0;    // X coordinate
>>  origin[1] = 0.0;    // Y coordinate
>>  origin[2] = 0.0;    // Z coordinate
>>  importer->SetOrigin( origin );
>> 
>>  double spacing[ Dimension ];
>>  spacing[0] = 1.0;    // along X direction
>>  spacing[1] = 1.0;    // along Y direction
>>  spacing[2] = 1.0;    // along Z direction
>>  importer->SetSpacing( spacing );
>>
>>  const bool importFilterWillDeleteTheInputBuffer = false;
>>  PixelType * pixeldata = static_cast< PixelType * >( fdata );
>>  const unsigned int numberOfPixels =  size[0] * size[1] * size[2];
>> 
>>  importer->SetImportPointer( pixeldata, numberOfPixels,
>>                                  importFilterWillDeleteTheInputBuffer );
>>  importer->Update();
>>
>>// ****************************************************************
>>//                      End preliminaries                                *
>>// ****************************************************************
>>//
>>//                    THRESHOLDING EXAMPLE
>>
>>typedef itk::ThresholdImageFilter< ImageType >  FilterType; 
>>FilterType::Pointer filter = FilterType::New();
>>filter->SetInput( importer->GetOutput() ); ThresholdBelow( 180 ); 
>>filter->Update();
>>//
>>// **************************************************************
>>//                          End Filter                                    *
>>// **************************************************************
>>//
>>// **************************************************************
>>//                              Write back to array                   *
>>// **************************************************************
>>ImageType::PixelContainer * container; container = 
>>filter->GetOutput()->GetPixelContainer();
>>container->SetContainerManageMemory( false );
>>fdata = container->GetImportPointer(); // // }
>>
>>
>>
>>Best Regards,
>>Dan
>>Daniel R Einstein, PhD
>>Biological Monitoring and Modeling
>>Pacific Northwest National Laboratory
>>P.O. Box 999; MSIN P7-59
>>Richland, WA 99352
>>Tel: 509/ 376-2924
>>Fax: 509/376-9064
>>_daniel.einstein at pnl.gov_ <mailto:daniel.einstein at pnl.gov>
>>
>>
>>
>>----------------------------------------------------------------------
>>--
>>
>>_______________________________________________
>>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