[Insight-users] reply to adaptive threshold filter
robert tamburo
robert.tamburo at gmail.com
Fri May 20 11:00:01 EDT 2011
There are non-zero pixels in your image. They have a value of 1. You need to
rescale the intensities (in code or in viewer) to visualize them. Or you
could set the inside value to 255 instead of 1.
2011/5/20 Quan <mrvillage at 163.com>
> hello robert,
> you're right.i set the number of control points as you suggested,it run
> smoothly,but the output image is awful,it's just a black images,all pixels
> value are 0,i just dont know why!what about your result?i have tried several
> images,but the results are all same ,they are black.i'm confused!
> thanks
> Quan
>
> At 2011-05-20 21:36:59,"robert tamburo" <robert.tamburo at gmail.com> wrote:
>
> Thanks for sending the code. Your input image wasn't attached, but I was
> able to recreate the error with my own image. I lowered the number of
> control points to 10 and the code executed without error.
>
> 2011/5/19 Quan <mrvillage at 163.com>
>
>> oh,i retry once more but failed again.my environment is
>> Windows7+win32+VS2010+itk.i can get through the compile and bulid
>> process.however,when i run the prog,the error occures.i cut a picture that
>> descibes the error in attachment .also,my input image HE.png is 2D unsigned
>> char type.
>> i list my source code bellow:
>> #include "itkImage.h"
>> #include <iostream>
>> #include "itkAdaptiveOtsuThresholdImageFilter.h"
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>> using namespace std;
>> void AdaptiveOtsuThresholdImage(
>> const std::string & inputFileName,
>> const std::string & outputFileName,
>> const unsigned int & radius,
>> const unsigned int & bins,
>> const unsigned int & controlPoints,
>> const unsigned int & levels,
>> const unsigned int & samples,
>> const unsigned int & splineOrder );
>> int main()
>> {
>> AdaptiveOtsuThresholdImage("HE.png","Output.png",20,256,30,3,12,3);
>> return 1;
>> }
>> void AdaptiveOtsuThresholdImage(
>> const std::string & inputFileName,
>> const std::string & outputFileName,
>> const unsigned int & radius,
>> const unsigned int & bins,
>> const unsigned int & controlPoints,
>> const unsigned int & levels,
>> const unsigned int & samples,
>> const unsigned int & splineOrder )
>> {
>> /** Typedef's. */
>> const unsigned int ImageDimension = 2;
>> typedef unsigned char OutputPixelType;
>> typedef itk::Image< OutputPixelType, ImageDimension > InputImageType;
>> typedef itk::Image< OutputPixelType, ImageDimension > OutputImageType;
>> typedef itk::ImageFileReader< InputImageType > ReaderType;
>> typedef itk::AdaptiveOtsuThresholdImageFilter<
>> InputImageType, OutputImageType> ThresholderType;
>> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>> typedef ThresholderType::InputSizeType RadiusType;
>> /** Declarations. */
>> ReaderType::Pointer reader = ReaderType::New();
>> ThresholderType::Pointer thresholder = ThresholderType::New();
>> WriterType::Pointer writer = WriterType::New();
>> RadiusType Radius; Radius.Fill( radius );
>> /** Read in the inputImage. */
>> reader->SetFileName( inputFileName.c_str() );
>> thresholder->SetInput( reader->GetOutput() );
>> /** Apply the threshold. */
>> thresholder->SetRadius( Radius );
>> thresholder->SetNumberOfHistogramBins( bins );
>> thresholder->SetNumberOfControlPoints( controlPoints );
>> thresholder->SetNumberOfLevels( levels );
>> thresholder->SetNumberOfSamples( samples );
>> thresholder->SetSplineOrder( splineOrder );
>> thresholder->SetInsideValue( 1 );
>> thresholder->SetOutsideValue( 0 );
>> /** Write the output image. */
>> writer->SetInput( thresholder->GetOutput() );
>> writer->SetFileName( outputFileName.c_str() );
>> try
>> {
>> writer->Update();
>> }
>> catch( itk::ExceptionObject & excep )
>> {
>> std::cerr << "Exception caught !" << std::endl;
>> std::cerr << excep << std::endl;
>> }
>> }
>>
>> At 2011-05-20 00:42:58,"robert tamburo" <robert.tamburo at gmail.com> wrote:
>>
>> I have not encountered this error. I have used this filter on a 2D,
>> unsigned char image with the following chunk of code:
>> AdaptiveThresholdFilterType::Pointer adaptiveThresholder=
>> AdaptiveThresholdFilterType::New();
>> adaptiveThresholder->SetInput(image);
>> adaptiveThresholder->SetInsideValue(255); // foreground of output image
>> adaptiveThresholder->SetOutsideValue(0); // background of output image
>> adaptiveThresholder->SetNumberOfHistogramBins(256);
>> adaptiveThresholder->SetNumberOfControlPoints(10); // b-spline control
>> points
>> adaptiveThresholder->SetNumberOfLevels(3); // number of b-spline levels
>> for reconstruction (3-5)
>> adaptiveThresholder->SetNumberOfSamples(12); // number of points to
>> randomly sample
>> CharImageType::SizeType radius;
>> radius[0] = 20;
>> radius[1] = 20;
>> adaptiveThresholder->SetRadius(radius); // radius of sampling region
>> adaptiveThresholder->Update();
>>
>> It would be helpful if you could make available (minimal) code and an
>> image that exhibits your problem (code and pictures are close to
>> universal!). Also, keep the discussion on the list.
>>
>> 2011/5/19 Quan <mrvillage at 163.com>
>>
>>> hi robert tamburo:
>>> thanks for your help.in fact ,i also read the paper,and downnload the
>>> code at
>>> http://praxix.googlecode.com/svn/trunk/src/thresholdimage/
>>> but what bothers me is that some errors occured when i run the project,it
>>> makes so
>>> upset as i don't know much about itk ,so i don't know how to debug it.
>>>
>>> the error is located at *itkBSplineScatteredDataPointSetToImageFilter.txx
>>> *" *Description:itk::ERROR::PointSetToImageFilter<027CFD18>:The
>>> Collapse point component 108 is outside the corrseponding parametric domain
>>> of [0,108] " *.have you ever met this kind of error,it seems that some
>>> other guy has the same problem with this filer,so i wanna a alternative
>>> mathod.Can u point out where is wrong and give me some advice?as i not
>>> native english speeker so it's hard for me to get the useful infomation by
>>> searching the internet,and also ,you may fell hard to read my e-mail,but i
>>> will be appreaciate for your help.
>>>
>>> in addition ,how do you think about my
>>> english,bad,so-so,good,excellent,or D,C,B,A?
>>>
>>> thanks.
>>>
>>>
>>>
>>
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110520/c5c64a26/attachment-0001.htm>
More information about the Insight-users
mailing list