[Insight-users] Problem with PasteImageFilter

Robert Jason Harris rjharris at fas.harvard.edu
Fri Jul 13 12:11:28 EDT 2007


Hi All,

I am trying to filter an image region by region.  For this purpose, I declare a
filter, the RegionOfInterestFitler, put my image through it, ThresholdFilter
the output of that, and then try to paste the output of the ThresholdFilter
back onto the image.  My (relevant) code is as follows:

size is the size of the image (2-D), size_box is the size of the (rectangular)
regions I want to filter the image by.


// all the stuff before this

	paste_filter->SetDestinationImage(reader->GetOutput());


	while((j < size[1]/size_box[1])){

		while((i < size[0]/size_box[0])){

			start[0] = i * size_box[0];
			start[1] = j * size_box[1];

			desiredRegion.SetIndex(start);

			filter->SetRegionOfInterest(desiredRegion);
			filter->SetInput(reader->GetOutput());
			region_of_interest = filter->GetOutput();

		   // Now, we have filtered out all stuff not in
          // our region of interest and put the filtered

          // perform statistics

			th_filter->SetInput(region_of_interest);
			th_filter->SetOutsideValue(0);
			th_filter->ThresholdBelow((something based on stats of image));
			th_filter->Update();

			paste_filter->SetSourceImage(th_filter->GetOutput());
			paste_filter->SetDestinationIndex(start);
			paste_filter->UpdateLargestPossibleRegion();

			i++;
		}
		i=0;
		j++;
	}

	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName(argv[2]);
	writer->SetInput(paste_filter->GetOutput());

	try{
		writer->Update();
	}
	catch( itk::ExceptionObject & exp){
		std::cerr<<"Exception caught at writer!"<<endl;
		std::cerr<< exp <<endl;
	}

When I do this, all I get is the same as my input image.  And, when I changed
the paster to take as the Destination a new image (declared within the program,
and blank), the output was a blank image.  So, I'm kinda stuck.  Any help is
appreciated.

Thanks!

Robert Harris




More information about the Insight-users mailing list