itk::Statistics::ListSample< itk::Vector< double, 1 > >::Pointer pdp::EMClassification::prepareSample(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask) { typedef itk::Vector< double, 1 > MeasurementVectorType; typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType; typedef itk::Image<unsigned char, 3> MaskType; typedef itk::Image<float, 3> ImageType; SampleType::Pointer sample = SampleType::New(); typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType; ImageIteratorType imgIt(img, img->GetLargestPossibleRegion()); typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType; MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion()); MeasurementVectorType mv; for ( imgIt.GoToBegin(), maskIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt) { if (maskIt.Get() == 255) { mv[0] = imgIt.Get(); sample->PushBack( mv ); } } return sample; }
// ------------------------------------------------------------------------ void computeProbImage(const PatchParams ¶ms, unsigned int pnum, unsigned int id, std::string type, ClassifierMap &classifiers, const ValveType::Pointer &valve, const LabelType::Pointer &mask, RealImageType::Pointer &output) { output = RealImageType::New(); output->SetDirection(mask->GetDirection()); output->SetSpacing(mask->GetSpacing()); output->SetOrigin(mask->GetOrigin()); output->SetRegions(mask->GetLargestPossibleRegion()); output->Allocate(); output->FillBuffer(0); itk::ImageRegionIterator<LabelType> maskIt(mask, mask->GetLargestPossibleRegion()); itk::ImageRegionIterator<RealImageType> probIt(output, output->GetLargestPossibleRegion()); unsigned int count = 0; while(!maskIt.IsAtEnd()) { if(maskIt.Get() == 255) { IndexType index = maskIt.GetIndex(); PointType point; output->TransformIndexToPhysicalPoint(index, point); MatrixType feature; extractLBPFeature(params, valve, point, feature); MatrixType probs; IntMatrixType classes; classifiers["MV-"+type][pnum]->PredictProbability(feature, classes, probs); probIt.Set(probs(0,1)); count++; } ++maskIt; ++probIt; } }
itk::Image<unsigned char, 3>::Pointer pdp::EMClassification::classify(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask) { typedef itk::Vector< double, 1 > MeasurementVectorType; typedef itk::Image<unsigned char, 3> MaskType; typedef itk::Image<float, 3> ImageType; typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType; ImageIteratorType imgIt(img, img->GetLargestPossibleRegion()); typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType; MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion()); MaskType::Pointer correctImage = MaskType::New(); correctImage->CopyInformation(mask); MaskType::RegionType outputRegion = mask->GetLargestPossibleRegion(); correctImage->SetRegions( outputRegion ); correctImage->Allocate(); typedef itk::ImageRegionIterator<MaskType> IteratorType; IteratorType outputIt( correctImage, outputRegion); MeasurementVectorType mv; for ( imgIt.GoToBegin(), maskIt.GoToBegin(), outputIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt, ++outputIt) { if (maskIt.Get() == 255) { mv[0] = imgIt.Get(); if (genLabel(mv) == 3) { outputIt.Set(255); } } } return correctImage; }
mitk::VolumeVisualizationImagePreprocessor::CTImage::Pointer VolumeVisualizationImagePreprocessor::Composite( CTImage::Pointer work, BinImage::Pointer mask, BinImage::Pointer dilated, BinImage::Pointer eroded) { VVP_INFO << "Compositing..."; /* itk::OrImageFilter<CTImage, CTImage, CTImage>::Pointer nullFilter= itk::OrImageFilter<CTImage, CTImage, CTImage>::New(); nullFilter->SetInput1( input ); nullFilter->SetInput2( input ); nullFilter->UpdateLargestPossibleRegion(); CTImage::Pointer work = nullFilter->GetOutput(); */ CTIteratorIndexType workIt( work, work->GetRequestedRegion() ); BinIteratorType maskIt( mask, mask->GetRequestedRegion() ); BinIteratorType dilateIt( dilated, dilated->GetRequestedRegion() ); BinIteratorType erodeIt( eroded, eroded->GetRequestedRegion() ); workIt.GoToBegin(); maskIt.GoToBegin(); dilateIt.GoToBegin(); erodeIt.GoToBegin(); double sum=0; int num=0; double sumIn=0; int numIn=0; int _min=32767,_max=-32768; total=0; memset(histogramm,0,sizeof(int)*65536); while ( ! ( workIt.IsAtEnd() || maskIt.IsAtEnd() || dilateIt.IsAtEnd() || erodeIt.IsAtEnd() ) ) { int value = workIt.Get(); unsigned char mask = maskIt.Get(); unsigned char dilate = dilateIt.Get(); unsigned char erode = erodeIt.Get(); //baut Histogramm auf vom Leberinneren if(mask != 0) { sumIn+=value; numIn++; histogramm[32768+(int)value]++; total++; } //Mittelwert der äußeren Schicht if(erode != 0 && mask != 0 ) { sum+=value; num++; if(value>_max) _max=value; if(value<_min) _min=value; } //markiere Leberoberfläche mit -1024 und update bounding box if(erode == 0 && dilate != 0 ) { value = -1024; } else if( erode != 0 && mask != 0 )//Leberinneres, behalte Grauwert bei { } else//markiere äußeres mit -2048 { value = -2048; } workIt.Set(value); ++workIt; ++maskIt; ++dilateIt; ++erodeIt; } VVP_INFO << "liver consists of " << total << " samples."; m_GreatestStructureThreshold = GetHistogrammValueFromTop(0.20); m_EstimatedThreshold = GetHistogrammValueFromTop(0.10); m_MaxThreshold=GetHistogrammValueFromTop(0.001); m_MinThreshold=GetHistogrammValueFromBottom(0.20); VVP_INFO << "threshold range: (" << m_MinThreshold << ";" << m_MaxThreshold << ") estimated vessel threshold: " << m_EstimatedThreshold ; VVP_INFO << "m_GreatestStructureThreshold: " << m_GreatestStructureThreshold; // BinImage::Pointer binImageThreshold= Threshold(work,m_GreatestStructureThreshold ); // LabelImage::Pointer LabelImageunsorted=ConnectComponents(binImageThreshold); // LabelImage::Pointer LabelImageSorted= RelabelComponents(LabelImageunsorted); if(num>0) m_realSurfaceValue=sum/num; else m_realSurfaceValue=0; if(numIn>0) m_realInLiverValue=sumIn/numIn; else m_realInLiverValue=0; m_surfaceValue = _min - 40; m_OutOfLiverValue = m_surfaceValue - 40; // LabelIteratorType labelIt( LabelImageSorted, LabelImageSorted->GetRequestedRegion() ); workIt.GoToBegin(); // labelIt.GoToBegin(); //int numGesetzt=0; //int numGelassen=0; while ( ! workIt.IsAtEnd() ) { int value = workIt.Get(); // int label = labelIt.Get(); if(value == -1024 ) { value = m_surfaceValue; } else if( value == -2048 ) { value = m_OutOfLiverValue; } else {//innerhalb der Leber //Label ungleich 1 -->value auf min setzen /* if (label != 1){ numGesetzt++; value=m_realInLiverValue; } else { //value=m_EstimatedThreshold; numGelassen++; } */ } workIt.Set(value); ++workIt; // ++labelIt; } //VVP_INFO << "gesetzt: " << numGesetzt << " --- gelassen: " << numGelassen; VVP_INFO << "OutOfLiver value: " << m_OutOfLiverValue; VVP_INFO << "surface value: " << m_surfaceValue; VVP_INFO << "real surface value: " << m_realSurfaceValue; VVP_INFO << "real inLiver value:" << m_realInLiverValue; work->DisconnectPipeline(); return work; }
void VolumeVisualizationImagePreprocessor::DetermineBoundingBox( BinImage::Pointer mask ) { VVP_INFO << "determining Bounding Box..."; BinIteratorIndexType maskIt( mask, mask->GetRequestedRegion() ); maskIt.GoToBegin(); int totalMinX; int totalMinY; int totalMinZ; int totalMaxX; int totalMaxY; int totalMaxZ; // Initialize Bounding Box { m_MinX=m_MinY=m_MinZ = 1000000; m_MaxX=m_MaxY=m_MaxZ = -1000000; totalMinX=totalMinY=totalMinZ = 1000000; totalMaxX=totalMaxY=totalMaxZ = -1000000; } while ( ! maskIt.IsAtEnd() ) { BinIteratorIndexType::IndexType idx = maskIt.GetIndex(); int x=idx.GetElement(0); int y=idx.GetElement(1); int z=idx.GetElement(2); if(x<totalMinX) totalMinX=x; if(y<totalMinY) totalMinY=y; if(z<totalMinZ) totalMinZ=z; if(x>totalMaxX) totalMaxX=x; if(y>totalMaxY) totalMaxY=y; if(z>totalMaxZ) totalMaxZ=z; if(maskIt.Get()) { if(x<m_MinX) m_MinX=x; if(y<m_MinY) m_MinY=y; if(z<m_MinZ) m_MinZ=z; if(x>m_MaxX) m_MaxX=x; if(y>m_MaxY) m_MaxY=y; if(z>m_MaxZ) m_MaxZ=z; } ++maskIt; } int border = 3; m_MinX -= border; if(m_MinX < totalMinX ) m_MinX = totalMinX; m_MinY -= border; if(m_MinY < totalMinY ) m_MinY = totalMinY; m_MinZ -= border; if(m_MinZ < totalMinZ ) m_MinZ = totalMinZ; m_MaxX += border; if(m_MaxX > totalMaxX ) m_MaxX = totalMaxX; m_MaxY += border; if(m_MaxY > totalMaxY ) m_MaxY = totalMaxY; m_MaxZ += border; if(m_MaxZ > totalMaxZ ) m_MaxZ = totalMaxZ; VVP_INFO << "Bounding box" << " m_MinX: " << m_MinX << " m_MaxX: " << m_MaxX << "\n m_MinY: " << m_MinY << " m_MaxY: " << m_MaxY << "\n m_MinZ: " << m_MinZ << " m_MaxZ: " << m_MaxZ; }