ImageType::Pointer SBFilterUtils::ThresholdImage(ImageType::Pointer image, int lowerThreshold, int upperThreshold, int insideValue, int outsideValue) { BinaryThresholdFilterType::Pointer thresholdFilter = BinaryThresholdFilterType::New(); thresholdFilter->SetInput(image); thresholdFilter->SetLowerThreshold(lowerThreshold); thresholdFilter->SetUpperThreshold(upperThreshold); thresholdFilter->SetOutsideValue(outsideValue); thresholdFilter->SetInsideValue(insideValue); thresholdFilter->Update(); return thresholdFilter->GetOutput(); }
void BinaryThresholdFilterDialog::on_pushButtonApply_clicked() { ImageLayer *imageLayer = ImageLayer::instance(); int insideValue = ui->spinBoxInsideValue->value(); int outsideValue = ui->spinBoxOutsideValue->value(); int lowerThreshold = ui->spinBoxLowerThreshold->value(); int upperThreshold = ui->spinBoxUpperThreshold->value(); imageLayer->resizeImageVector(2); typedef itk::BinaryThresholdImageFilter<ImageLayer::GrayImageType, ImageLayer::GrayImageType> BinaryThresholdFilterType; BinaryThresholdFilterType::Pointer binaryThresholdFilter = BinaryThresholdFilterType::New(); binaryThresholdFilter->SetInsideValue(insideValue); binaryThresholdFilter->SetOutsideValue(outsideValue); binaryThresholdFilter->SetLowerThreshold(lowerThreshold); binaryThresholdFilter->SetUpperThreshold(upperThreshold); binaryThresholdFilter->SetInput(imageLayer->grayImagePointer(0)); binaryThresholdFilter->Update(); imageLayer->setGrayImage(1, binaryThresholdFilter->GetOutput()); }
void WholeCellSeg::SyntheticBoundaries(){ typedef itk::RescaleIntensityImageFilter< UShortImageType, IntImageType > RescaleIOIntType; typedef itk::RescaleIntensityImageFilter< FltImageType, IntImageType > RescaleFltIntType; typedef itk::CastImageFilter< UShortImageType, IntImageType > CastUSIntType; typedef itk::CastImageFilter< IntImageType, UShortImageType > CastIntUSType; typedef itk::BinaryThresholdImageFilter< IntImageType, IntImageType > BinaryThresholdFilterType; typedef itk::BinaryThresholdImageFilter< FltImageType, IntImageType > BinaryThresholdFilterTypeFI; typedef itk::AndImageFilter< IntImageType, IntImageType, IntImageType > AndFilterType; typedef itk::SignedMaurerDistanceMapImageFilter< IntImageType, FltImageType > SignedMaurerDistanceMapFilterType; typedef itk::MorphologicalWatershedFromMarkersImageFilter< IntImageType, IntImageType > WatershedFilterType; typedef itk::ImageRegionIteratorWithIndex< UShortImageType > IteratorType; typedef itk::ImageRegionIteratorWithIndex< IntImageType > IteratorType1; //Rescale and Threshold input label image RescaleIOIntType::Pointer RescaleIOInt = RescaleIOIntType::New(); RescaleIOInt->SetOutputMaximum( INT_MAX ); RescaleIOInt->SetOutputMinimum( 0 ); RescaleIOInt->SetInput( nuclab_inp ); if( draw_real_bounds && remove_small_objs ) RescaleIOInt->SetInput( nuclab_inp_cpy ); else RescaleIOInt->SetInput( nuclab_inp ); RescaleIOInt->Update(); BinaryThresholdFilterType::Pointer binarythreshfilter = BinaryThresholdFilterType::New(); binarythreshfilter->SetInsideValue( INT_MAX ); binarythreshfilter->SetOutsideValue( 0 ); binarythreshfilter->SetLowerThreshold( 1 ); binarythreshfilter->SetUpperThreshold( INT_MAX ); binarythreshfilter->SetInput( RescaleIOInt->GetOutput() ); binarythreshfilter->Update(); //Distance map for synthetic boundaries around nuclei that do not have any marker around them SignedMaurerDistanceMapFilterType::Pointer distancemapfilter = SignedMaurerDistanceMapFilterType::New(); distancemapfilter->SetInput(binarythreshfilter->GetOutput()); distancemapfilter->SquaredDistanceOff(); distancemapfilter->Update(); //Threshold the map to limit the max distance to the radius limit set by the user BinaryThresholdFilterTypeFI::Pointer binarythreshfilterfi = BinaryThresholdFilterTypeFI::New(); binarythreshfilterfi->SetInsideValue( INT_MAX ); binarythreshfilterfi->SetOutsideValue( 0 ); binarythreshfilterfi->SetLowerThreshold( 1 ); binarythreshfilterfi->SetUpperThreshold( radius_of_synth_bounds ); binarythreshfilterfi->SetInput( distancemapfilter->GetOutput() ); RescaleFltIntType::Pointer rescalefltint = RescaleFltIntType::New(); rescalefltint->SetOutputMaximum( INT_MAX ); rescalefltint->SetOutputMinimum( 0 ); rescalefltint->SetInput( distancemapfilter->GetOutput() ); AndFilterType::Pointer andfilter1 = AndFilterType::New(); andfilter1->SetInput1( rescalefltint->GetOutput() ); andfilter1->SetInput2( binarythreshfilterfi->GetOutput() ); AndFilterType::Pointer andfilter2 = AndFilterType::New(); andfilter2->SetInput1( andfilter1->GetOutput() ); andfilter2->SetInput2( binarythreshfilterfi->GetOutput() ); andfilter2->Update(); CastUSIntType::Pointer castUSIntfilter = CastUSIntType::New(); if( draw_real_bounds && remove_small_objs ) castUSIntfilter->SetInput( nuclab_inp_cpy ); else castUSIntfilter->SetInput( nuclab_inp ); castUSIntfilter->Update(); IntImageType::Pointer nuclab_inp_int = IntImageType::New(); nuclab_inp_int = castUSIntfilter->GetOutput(); IntImageType::Pointer image2=andfilter2->GetOutput(); IteratorType1 pix_bufed2( image2, image2->GetRequestedRegion() ); pix_bufed2.GoToBegin(); IteratorType1 pix_bufed3( nuclab_inp_int, nuclab_inp_int->GetRequestedRegion() ); pix_bufed3.GoToBegin(); while( !pix_bufed2.IsAtEnd() || !pix_bufed3.IsAtEnd() ){ if( !pix_bufed2.Get() ) if( !pix_bufed3.Get() ) pix_bufed2.Set( INT_MIN ); ++pix_bufed2; ++pix_bufed3; } //Draw synthetic boundaries using the seeded Watershed algorithm WatershedFilterType::Pointer watershedfilter = WatershedFilterType::New(); watershedfilter->SetInput1( image2 ); watershedfilter->SetInput2( nuclab_inp_int ); watershedfilter->SetMarkWatershedLine( 1 ); watershedfilter->Update(); CastIntUSType::Pointer castIntUSfilter = CastIntUSType::New(); castIntUSfilter->SetInput( watershedfilter->GetOutput() ); castIntUSfilter->Update(); if( draw_real_bounds ){ UShortImageType::Pointer image1=castIntUSfilter->GetOutput(); IteratorType pix_bufed( image1, image1->GetRequestedRegion() ); pix_bufed.GoToBegin(); IteratorType pix_bufed1( seg_im_out, seg_im_out->GetRequestedRegion() ); pix_bufed1.GoToBegin(); while( !pix_bufed1.IsAtEnd() ){ if( !pix_bufed1.Get() ) pix_bufed1.Set( pix_bufed.Get()); ++pix_bufed; ++pix_bufed1; } } else seg_im_out = castIntUSfilter->GetOutput(); /* IteratorType1 pix_bufed33( image2, image2->GetRequestedRegion() ); pix_bufed33.GoToBegin(); while( !pix_bufed33.IsAtEnd() ){ if( 0 > pix_bufed33.Get() ) pix_bufed33.Set(0); ++pix_bufed33; } typedef itk::RescaleIntensityImageFilter< IntImageType, UShortImageType > RescaleIntIOType; RescaleIntIOType::Pointer RescaleIntIO1 = RescaleIntIOType::New(); RescaleIntIO1->SetOutputMaximum( USHRT_MAX ); RescaleIntIO1->SetOutputMinimum( 0 ); RescaleIntIO1->SetInput( image2 ); //watershedfilter->GetOutput() image1 RescaleIntIO1->Update(); typedef itk::ImageFileWriter< UShortImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName( "dist_map.tif" ); writer->SetInput( RescaleIntIO1->GetOutput() );//RescaleIntIO1--finalO/P writer->Update(); */ if( ( !remove_small_objs ) || ( draw_real_bounds && remove_small_objs ) ) seg_done = 1; }