[ITK-users] Issue with BinaryDilate(Erode)ImageFilter with not "0/255" binary image

Matt McCormick matt.mccormick at kitware.com
Fri Jun 5 18:25:39 EDT 2015


Hi Zagwin,

Yes, you will need to specify the foreground values for binary
filters.  The do not have a way to determine the values otherwise.

Hope this helps,
Matt

On Fri, Jun 5, 2015 at 5:49 PM, zagwin <zagwin at gmail.com> wrote:
> Hello,
>
> It seems I found an interesting problem (actually, I don't know if it is
> real problem).
> I found whenever I input an not 0/255 binary image, such as 0/1 image, or
> 0/127 image, nothing changed (this can be solved by SetDilateValue(1)).
> However, I thought it is two-value binary image, I don't need to set this
> value as wiki example showed. Am I right?
>
> My simple code is as below:
>
> int foreground = 255; // I tried 1 and 127, not work
> typedef signed short                         InputPixelType;
> typedef unsigned char                      UCharPixelType;
> static const unsigned int InputDimension = 2;//Dimension of image
> typedef itk::Image< InputPixelType, InputDimension > InputImageType;//Image
> Type
> typedef itk::Image< UCharPixelType, InputDimension > UCharImageType;
>
> typedef itk::ImageFileReader<InputImageType>   ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> m_itkImage = InputImageType::New();
> reader->SetFileName("MG0244.dcm");
> reader->Update();
> m_itkImage->Graft(reader->GetOutput());
>
>
> typedef itk::BinaryThresholdImageFilter     <InputImageType, UCharImageType>
> BinaryThresholdFilterType;
> typedef itk::BinaryBallStructuringElement   <UCharPixelType, InputDimension>
> StructuringElementType;
> typedef itk::BinaryDilateImageFilter        <UCharImageType, UCharImageType,
> StructuringElementType> BinaryDilateFilterType;
> typedef itk::BinaryErodeImageFilter         <UCharImageType, UCharImageType,
> StructuringElementType> BinaryErodeFilterType;
>
> typedef itk::ImageToVTKImageFilter<UCharImageType> ConnectorType2;
> ConnectorType2::Pointer connector2 = ConnectorType2::New();
> vtkSmartPointer<vtkImageData> mask  = vtkSmartPointer<vtkImageData>::New();
>
> BinaryThresholdFilterType::Pointer    btfilter1  =
> BinaryThresholdFilterType::New();
> BinaryDilateFilterType::Pointer       bDilate1   =
> BinaryDilateFilterType::New();
> BinaryErodeFilterType::Pointer       bErode1   =
> BinaryErodeFilterType::New();
>
> btfilter1->SetLowerThreshold(100);
> btfilter1->SetUpperThreshold(500);
> btfilter1->SetInsideValue(foreground);
> btfilter1->SetOutsideValue(0);
>
> StructuringElementType element1;
> element1.SetRadius(3);
> element1.CreateStructuringElement();
> bDilate1->SetKernel(element1);
> bErode1->SetKernel(element1);
> //bDilate1->SetDilateValue(foreground);  //these two lines solve the problem
> of non-255 values
> //bErode1->SetErodeValue(foreground);
>
> btfilter1->SetInput(m_itkImage.GetPointer());
> bDilate1->SetInput(btfilter1->GetOutput());
> bErode1->SetInput(btfilter1->GetOutput());
>
> connector2->SetInput( /*bErode1*/ bDilate1->GetOutput() );
> connector2->Update();
> mask->DeepCopy(connector2->GetOutput());
>
> image_view->SetInputData(mask);
> image_view->GetRenderer()->ResetCamera();
> image_view->Render();
>
>
>
>
>
>
>
> --
> View this message in context: http://itk-users.7.n7.nabble.com/Issue-with-BinaryDilate-Erode-ImageFilter-with-not-0-255-binary-image-tp35774.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users


More information about the Insight-users mailing list