[Insight-users] OTSU test code

Luis Ibanez luis.ibanez@kitware.com
Fri, 20 Sep 2002 17:26:17 -0400


Hi Uday


ITK Calculators are not ProcessObjects as ImageFilters are.

The consequence of that is that Calculators do not trigger
updates in the pipeline.  This is usually fine since
Calculators are intended to be helper classes inside
actual filters.


What happens in your code example is that To ITK the
pipeline look like:



  Reader ---->O-----> Writer
              |
              |
              V
          Calculator



The reader will only read the image when its "Update()"
method is invoked.  A call to writer->Write() will
trigger the pipeline update mechanism an produce a
call to reader->Update().

The calculator on the other hand, not being a ProcessObject
will just rely on the image to be available at the reader
output.


If you call directly "Update()" on the reader before
invoking "Compute()" on the Calculator, the process
should work just fine.

Also, note that for PNG, VTK, Meta and Dicom you no
longer need to explicity specify the IO object nor
the IO factory. Default factories for these formats
are now registered at construction time in the IO
framework.

The following code should be enough:



   reader->SetFileName("input.png");
   reader->Update();
   calculator->SetInput( reader->GetOutput() );
   calculator->Compute();
   PixelType threshold = calculator->GetThreshold();




Please let us know if you find further problems

   Thanks


    Luis


==========================================


Uday Kurkure wrote:

> 
> 
> Hello all,
> 
> Thanks Louis and Sayan for your suggestions.
> 
> I could successfully run the OTSU test code. Now I have modified it to 
> take a PNG image as input. It is working fine for this part of code:
> 
> //----------------------------------------------------------------
>   // Read in the image
>   itk::PNGImageIO::Pointer io;
>   io = itk::PNGImageIO::New();
>   typedef unsigned char PixelType;
>   typedef itk::Image<PixelType, 2> myImage;
>   itk::ImageFileReader<myImage>::Pointer input
>     = itk::ImageFileReader<myImage>::New();
>   input->SetFileName(av[0]);
>   input->SetImageIO(io);// comment it if using factory
> 
>   // write the input image
>   itk::ImageFileWriter<myImage>::Pointer writer1;
>   writer1 = itk::ImageFileWriter<myImage>::New();
>   writer1->SetInput(input->GetOutput());
>   writer1->SetFileName("myinput.png");
>   writer1->SetImageIO(io);// comment it if using factory
>   writer1->Write();
>   // Create and initialize the calculator
>   CalculatorType::Pointer calculator = CalculatorType::New();
>   calculator->SetImage(input->GetOutput());
>   calculator->SetNumberOfHistogramBins( 256);
>   calculator->Compute();
> //--------------------------------------------------------------
> 
> But if I don't write out the image (comment the writer1 code lines)
> it always give threshold 0. I want to remove the writing part. Can some 
> one suggest something.
> 
> Thanks,
> Uday Kurkure.
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>