[Insight-users] Re: problems with median filter

Carolyn Johnston Carolyn . Johnston at vexcel . com
Tue, 15 Jul 2003 17:17:08 -0600


Hi Luis,

I should say first that for some reason... I am not having the shift 
problem I described anymore. <<sigh>> It's like taking your car to the 
shop.. the only change was the call to Image::Print. Perhaps it's a quantum 
problem and simply trying to look at it fixes it? (Hm... are some of these 
quantities only calculated on the fly, as needed?)

>The main suspects here are the regions:
>
>    LargestPossibleRegion
>    BufferedRegion
>    RequestedRegion

I agree with you that these were the main worries, and thank you for 
pointing out a way that I can look at the values of these regions.

I've included two things here: one, my import function: two, the results 
you requested. The file "dem.raw" was created using an ImportImageFilter, 
and "post_dem.raw" are the results from the median filter.

______________________________________________________________
Here is the import function I use. ImageFilterType is typedef'd to 
MedianImageFilter. writeImage contains the call to print out the itk::IMage 
data.


GDALToITK::ImageFilterType::Pointer
GDALToITK::ImageFromDem(DemDataFloat& dem){

   typedef itk::ImportImageFilter<float, 2> ImportFilterType;
   ImportFilterType::Pointer importFilter = ImportFilterType::New();

  // set up image coordinate environment
  ImportFilterType::SizeType size;
  ImportFilterType::IndexType start;
  ImportFilterType::RegionType region;
  size[0]=dem.size.x;
  size[1]=dem.size.y;
  start.Fill(0);
  region.SetSize(size);
  region.SetIndex(start);
  importFilter->SetRegion(region);

  // set ground coordinate environment: origin and spacing
  double origin[2];
  double spacing[2];
  Dpoint2d geo_origin = dem.PixToGeo(Ipoint2d(0,0));
  origin[0]=geo_origin.x;
  origin[1]=geo_origin.y;
  Dpoint2d geo_spacing = GetCoordSpacing(dem);

  // cpj ++ 7.8.2003: added fabs to fix bug where registration code 
expected positive values.
  spacing[0]=fabs(geo_spacing.x);
  spacing[1]=fabs(geo_spacing.y);
  importFilter->SetOrigin(origin);
  importFilter->SetSpacing(spacing);

  printf("Image information: \n");
  printf("spacing: (%f, %f)\n", spacing[0], spacing[1]);
  printf("origin: (%f, %f)\n", origin[0], origin[1]);
  printf("size: (%u, %u)\n\n", (unsigned) size[0], (unsigned) size[1]);
  //copy dem data into ITK image.

  float *buffer;
  const int demsize=dem.imgdata.size();
  assert(demsize==size[0]*size[1]);
  if(demsize!=0)
    buffer = &(dem.imgdata[0]);
  else
    throw itk::ExceptionObject("Specify nonzero size for input DEM");

  // 'true' value means that importFilter won't delete buffer (which 
belongs to dem!) when it's destroyed
  importFilter->SetImportPointer(buffer, demsize, true);
  if(debug){
    writeImage(importFilter, "/home/cpj/tec_project/test/DemRegister/dem.raw");
  }

  // Instantiate a filter and attach it to the importer.
  // cpj: input type = ImageType =output image type.
  // have used gradient manitude and median filters here.
  ImageFilterType::Pointer filter = ImageFilterType::New();
  filter->SetInput(importFilter->GetOutput());

  //++ 7.15.2003: debug code
  importFilter->GetOutput()->Print(std::cout);
  // ++ cpj 7.15.2003 test: use only with ThresholdImageFilter
  // filter->SetOutsideValue(-1000);
  // filter->ThresholdBelow(-10000);
  // filter->ThresholdAbove(10000);

  if(debug){
    writeImage(filter, "/home/cpj/tec_project/test/DemRegister/post_dem.raw");
  }
  //++ 7.15.2003: debug code
  filter->GetOutput()->Print(std::cout);
  return filter;
} // end of function

_______________________________________________________________

output from the print statements:

(OUTPUT FROM IMPORT-FILTERED IMAGE -- I've checked this, there's no shift)
<GDALToITK::writeImage>: writing image 
/home/cpj/tec_project/test/DemRegister/dem.raw
Image (0x353b38)
   Reference Count: 2
   Modified Time: 30
   Debug: Off
   Observers:
     none
   Source: (0x3541e8)
   Source output index: 0
   Release Data: Off
   Data Released: False
   Global Release Data: Off
   PipelineMTime: 14
   UpdateTime: 32
   LastRequestedRegionWasOutsideOfTheBufferedRegion: 0
   LargestPossibleRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   BufferedRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   RequestedRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   Origin: [-122.999861, 45.999861]
   Spacing: [0.000278, 0.000278]
   PixelContainer: ImportImageContainer (0x3539f0)
   Reference Count: 2
   Modified Time: 31
   Debug: Off
   Observers:
     none
   Pointer: 0x353a1c
   Container manages memory: false
   Size: 12967201
   Capacity: 12967201


   IndexToPhysicalTransform: AffineTransform (0x353c00)
   Reference Count: 2
   Modified Time: 5
   Debug: Off
   Observers:
     none
   Matrix:
     0.000278 0.000000 -122.999861
     0.000000 0.000278 45.999861


   PhysicalToIndexTransform: AffineTransform (0x355480)
   Reference Count: 2
   Modified Time: 6
   Debug: Off
   Observers:
     none
   Matrix:
     3600.000000 0.000000 442799.499992
     0.000000 3600.000000 -165599.500001


(OUTPUT FROM MEDIAN FILTERED IMAGE -- does not contain shift any more!!!)
<GDALToITK::writeImage>: writing image 
/home/cpj/tec_project/test/DemRegister/post_dem.raw
Image (0x355630)
   Reference Count: 1
   Modified Time: 71
   Debug: Off
   Observers:
     none
   Source: (0x3555b8)
   Source output index: 0
   Release Data: Off
   Data Released: False
   Global Release Data: Off
   PipelineMTime: 56
   UpdateTime: 73
   LastRequestedRegionWasOutsideOfTheBufferedRegion: 0
   LargestPossibleRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   BufferedRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   RequestedRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [3601, 3601]
   Origin: [-122.999861, 45.999861]
   Spacing: [0.000278, 0.000278]
   PixelContainer: ImportImageContainer (0x353a38)
   Reference Count: 2
   Modified Time: 72
   Debug: Off
   Observers:
     none
   Pointer: 0x353a64
   Container manages memory: true
   Size: 12967201
   Capacity: 12967201
  IndexToPhysicalTransform: AffineTransform (0x3556f8)
   Reference Count: 2
   Modified Time: 48
   Debug: Off
   Observers:
     none
   Matrix:
     0.000278 0.000000 -122.999861
     0.000000 0.000278 45.999861


   PhysicalToIndexTransform: AffineTransform (0x355868)
   Reference Count: 2
   Modified Time: 49
   Debug: Off
   Observers:
     none
   Matrix:
     3600.000000 0.000000 442799.499992
     0.000000 3600.000000 -165599.500001