[Insight-users] OTSU test code & Tcl Wrapping
Luis Ibanez
luis.ibanez@kitware.com
Fri, 20 Sep 2002 18:37:55 -0400
Hi Uday,
BTW,
For users interested in Tcl wrapping,
Here is the how the equivalent code look like
with the wrappers generated by Cable:
First start: "itktcl"
then do:
package require InsightToolkit
set reader [ itk::create ImageFileReaderUS2 ]
$reader SetFileName "BrainSlice.png"
set otsuCalculator [ itk::create OtsuThresholdImageCalculatorUS2 ]
$reader Update
$otsuCalculator SetImage [ $reader GetOutput ]
$otsuCalculator Compute
set threshold [ $otsuCalculator GetThreshold ]
puts $threshold
Tcl wrapping is being configured for images of PixelTypes
"float" and "unsigned short" both in 2D and 3D.
The types are identified by the following terminations:
US2 = unsigned short 2D
US3 = unsigned short 3D
F2 = float 2D
F3 = float 3D
These types cover most of the common needs for rapid
prototyping.
"itk::create" is a helper mechanism that implements
the Tcl equivalent of calling ::New() in C++.
Luis
================================================
Luis Ibanez wrote:
>
> Hi Uday,
>
>
> The IO factories were added as default several weeks ago.
> (for PNG, Meta, Dicom and VTK).
>
>
> What version of ITK are you using ?
> if it is a CVS checkout, how recent it is ?
>
> You may want to risk updating from cvs. Just
> double check the ITK Dashboard before updating
> to make sure that you get a green version.
>
>
> Thanks,
>
>
> Luis
>
>
> ====================================================================
>
> Uday Kurkure wrote:
>
>>
>> Hi Louis,
>>
>> I am wondering how I forgot about Update() function. Thanks for
>> explaining me the pipeline. Will keep that in mind.
>> I added the Update() function and removed the writer part and BINGO!
>> it is working perfectly. But I get run-time error if I don't
>> explicitly specify the IO object/factory. It's fine with me to
>> explicitly specify them but since you mentioned that now we don't need
>> to specify them, I am curious how to make it work. Can you throw some
>> light on it?
>>
>> Thanks,
>> Uday Kurkure.
>>
>>
>>
>>> 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
>>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users@public.kitware.com
>> http://public.kitware.com/mailman/listinfo/insight-users
>>
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>