11 m_NumThreads = itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads();
21 m_ComputationMask = NULL;
23 m_WeightThreshold = 0.0;
24 m_MeanThreshold = 10.0;
25 m_VarianceThreshold = 10.0;
29 m_SearchNeighborhood = 4;
35 delete m_DatabaseImages;
40 if (m_DatabaseCovarianceDistanceAverage)
41 delete m_DatabaseCovarianceDistanceAverage;
43 if (m_DatabaseCovarianceDistanceStd)
44 delete m_DatabaseCovarianceDistanceStd;
46 if (m_DatabaseMeanDistanceAverage)
47 delete m_DatabaseMeanDistanceAverage;
49 if (m_DatabaseMeanDistanceStd)
50 delete m_DatabaseMeanDistanceStd;
55 m_ComputationMask = anima::readImage <MaskImageType> (cMask);
68 if (!m_ComputationMask)
69 itkExceptionMacro(
"No computation mask... Exiting...");
72 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
73 tmpInd[i] = m_NbSplits;
78 for (
unsigned int i = 0;i < MaskImageType::GetImageDimension();++i)
79 marginBlock[i] = std::max(m_SearchNeighborhood + m_PatchHalfSize,(
unsigned int)4);
95 std::vector < ImageSplitterType::TInputIndexType > splitIndexesToProcess;
97 if (specificSplitToDo != -1)
99 tmpInd[0] = (
unsigned int)floor((
double)(specificSplitToDo/(m_NbSplits*m_NbSplits)));
100 unsigned int tmpVal = specificSplitToDo - tmpInd[0]*m_NbSplits*m_NbSplits;
101 tmpInd[1] = (
unsigned int)floor((
double)(tmpVal/m_NbSplits));
102 tmpInd[2] = tmpVal - tmpInd[1]*m_NbSplits;
104 if (!m_DatabaseImages->
EmptyMask(tmpInd))
105 splitIndexesToProcess.push_back(tmpInd);
109 for (
unsigned int i = 0;i < m_NbSplits;++i)
112 for (
unsigned int j = 0;j < m_NbSplits;++j)
115 for (
unsigned int k = 0;k < m_NbSplits;++k)
119 if (!m_DatabaseImages->
EmptyMask(tmpInd))
120 splitIndexesToProcess.push_back(tmpInd);
126 for (
unsigned int i = 0;i < splitIndexesToProcess.size();++i)
128 std::cout <<
"Processing block : " << splitIndexesToProcess[i][0] <<
" " 129 << splitIndexesToProcess[i][1] <<
" " << splitIndexesToProcess[i][2] << std::endl;
132 m_DatabaseImages->
Update();
137 m_DatabaseCovarianceDistanceAverage->
SetBlockIndex(splitIndexesToProcess[i]);
138 m_DatabaseCovarianceDistanceAverage->
Update();
140 m_DatabaseCovarianceDistanceStd->
SetBlockIndex(splitIndexesToProcess[i]);
141 m_DatabaseCovarianceDistanceStd->
Update();
143 m_DatabaseMeanDistanceAverage->
SetBlockIndex(splitIndexesToProcess[i]);
144 m_DatabaseMeanDistanceAverage->
Update();
146 m_DatabaseMeanDistanceStd->
SetBlockIndex(splitIndexesToProcess[i]);
147 m_DatabaseMeanDistanceStd->
Update();
151 for (
unsigned int j = 0;j < m_DatabaseImages->
GetNbImages();++j)
152 mainFilter->AddDatabaseInput(m_DatabaseImages->
GetOutput(j));
155 mainFilter->SetNumberOfWorkUnits(m_NumThreads);
157 mainFilter->SetDatabaseMeanDistanceAverage(m_DatabaseMeanDistanceAverage->
GetOutput(0));
158 mainFilter->SetDatabaseMeanDistanceStd(m_DatabaseMeanDistanceStd->
GetOutput(0));
159 mainFilter->SetDatabaseCovarianceDistanceAverage(m_DatabaseCovarianceDistanceAverage->
GetOutput(0));
160 mainFilter->SetDatabaseCovarianceDistanceStd(m_DatabaseCovarianceDistanceStd->
GetOutput(0));
162 mainFilter->SetPatchHalfSize(m_PatchHalfSize);
163 mainFilter->SetSearchNeighborhood(m_SearchNeighborhood);
164 mainFilter->SetSearchStepSize(m_SearchStepSize);
165 mainFilter->SetWeightThreshold(m_WeightThreshold);
166 mainFilter->SetMeanThreshold(m_MeanThreshold);
167 mainFilter->SetVarianceThreshold(m_VarianceThreshold);
168 mainFilter->SetBetaParameter(m_BetaParameter);
170 mainFilter->SetInput(0,m_TestImage->
GetOutput(0));
172 mainFilter->Update();
174 std::cout <<
"Results computed... Writing output parcel..." << std::endl;
177 sprintf(numSplit,
"_%ld_%ld_%ld.nrrd",splitIndexesToProcess[i][0],splitIndexesToProcess[i][1],splitIndexesToProcess[i][2]);
180 std::string outputScoreName = m_OutputScoreName + numSplit;
181 std::string outputPValName = m_OutputPValName + numSplit;
182 std::string outputNPatchesName = m_OutputNPatchesName + numSplit;
185 if (m_OutputScoreName !=
"")
188 if (m_OutputNPatchesName !=
"")
192 if (genOutputDescriptionData)
194 std::vector <std::ofstream> mainOutFiles;
196 std::string tmpOutScoreName = m_OutputScoreName +
".txt";
197 std::ofstream tmpFileScoreOut;
199 if (m_OutputScoreName !=
"")
200 tmpFileScoreOut.open(tmpOutScoreName.c_str());
202 std::string tmpOutNPatchesName = m_OutputNPatchesName +
".txt";
203 std::ofstream tmpFileNPatchesOut;
205 if (m_OutputNPatchesName !=
"")
206 tmpFileNPatchesOut.open(tmpOutNPatchesName.c_str());
208 std::string tmpOutPValName = m_OutputPValName +
".txt";
209 std::ofstream tmpFilePValOut(tmpOutPValName.c_str());
211 for (
unsigned int i = 0;i < m_NbSplits;++i)
214 for (
unsigned int j = 0;j < m_NbSplits;++j)
217 for (
unsigned int k = 0;k < m_NbSplits;++k)
221 if (!m_DatabaseImages->
EmptyMask(tmpInd))
225 sprintf(numSplit,
"_%ld_%ld_%ld.nrrd",tmpInd[0],tmpInd[1],tmpInd[2]);
227 if (tmpFileScoreOut.is_open())
229 tmpFileScoreOut <<
"<BLOCK>" << std::endl;
230 tmpFileScoreOut <<
"BLOCK_FILE=" << m_OutputScoreName + numSplit << std::endl;
231 tmpFileScoreOut <<
"STARTING_INDEX=" << tmpBlRegion.GetIndex()[0] <<
" " 232 << tmpBlRegion.GetIndex()[1] <<
" " << tmpBlRegion.GetIndex()[2] << std::endl;
233 tmpFileScoreOut <<
"</BLOCK>" << std::endl;
236 if (tmpFileNPatchesOut.is_open())
238 tmpFileNPatchesOut <<
"<BLOCK>" << std::endl;
239 tmpFileNPatchesOut <<
"BLOCK_FILE=" << m_OutputNPatchesName + numSplit << std::endl;
240 tmpFileNPatchesOut <<
"STARTING_INDEX=" << tmpBlRegion.GetIndex()[0] <<
" " 241 << tmpBlRegion.GetIndex()[1] <<
" " << tmpBlRegion.GetIndex()[2] << std::endl;
242 tmpFileNPatchesOut <<
"</BLOCK>" << std::endl;
245 tmpFilePValOut <<
"<BLOCK>" << std::endl;
246 tmpFilePValOut <<
"BLOCK_FILE=" << m_OutputPValName + numSplit << std::endl;
247 tmpFilePValOut <<
"STARTING_INDEX=" << tmpBlRegion.GetIndex()[0] <<
" " 248 << tmpBlRegion.GetIndex()[1] <<
" " << tmpBlRegion.GetIndex()[2] << std::endl;
249 tmpFilePValOut <<
"</BLOCK>" << std::endl;
255 tmpFileNPatchesOut.close();
256 tmpFileScoreOut.close();
257 tmpFilePValOut.close();
262 OutputImageType::RegionType finalROI)
264 OutputImageType::RegionType tmpRegion = finalROI;
265 for (
unsigned int i = 0;i < OutputImageType::GetImageDimension();++i)
266 tmpRegion.SetIndex(i,0);
268 OutputImageType::Pointer tmpRes = OutputImageType::New();
269 tmpRes->Initialize();
271 tmpRes->SetOrigin(m_ComputationMask->GetOrigin());
272 tmpRes->SetRegions(tmpRegion);
273 tmpRes->SetDirection(m_ComputationMask->GetDirection());
274 tmpRes->SetSpacing(m_ComputationMask->GetSpacing());
278 itk::ImageRegionIterator <OutputImageType> tmpImIt (tmpIm,finalROI);
279 itk::ImageRegionIterator <OutputImageType> tmpResIt (tmpRes,tmpRegion);
281 while (!tmpImIt.IsAtEnd())
283 tmpResIt.Set(tmpImIt.Get());
289 anima::writeImage <OutputImageType> (resName,tmpRes);
292 void LowMemoryNLMeansPatientToGroupComparisonBridge::PrepareNoiseEstimates()
294 if (!m_ComputationMask)
295 itkExceptionMacro(
"No computation mask... Exiting...");
300 vnl_matrix <double> noiseCov;
302 for (
unsigned int k = 0;k < m_DatabaseImages->
GetNbImages();++k)
304 itk::ImageFileReader <InputImageType>::Pointer inReader = itk::ImageFileReader <InputImageType>::New();
305 inReader->SetFileName(m_DatabaseImages->
GetFileName(k));
TInputRegionType GetBlockRegionInsideMargin()
~LowMemoryNLMeansPatientToGroupComparisonBridge()
unsigned int GetNbImages()
void SetComputationMask(std::string &cMask)
MaskImageType * GetSmallMaskWithMargin()
NLMeansPatientToGroupComparisonImageFilter< double >::OutputImageType OutputImageType
void BuildAndWrite(OutputImageType *tmpIm, std::string resName, OutputImageType::RegionType finalROI)
void SetComputationMask(MaskImageType::Pointer &maskIm)
void SetBlockMargin(TInputIndexType &bMargin)
anima::ImageDataSplitter< OutputImageType > ScalarImageSplitterType
void Update(int specificSplitToDo=-1, bool genOutputDescriptionData=false)
void SetBlockIndex(TInputIndexType &bIndex)
itk::SmartPointer< Self > Pointer
void SetNumberOfBlocks(TInputIndexType &bNumBlocks)
anima::ImageDataSplitter< InputImageType > ImageSplitterType
TInputImage * GetOutput(unsigned int i)
TInputRegionType GetSpecificBlockRegion(TInputIndexType &block)
NLMeansPatientToGroupComparisonImageFilter< double >::OutputImageRegionType OutputImageRegionType
std::string GetFileName(unsigned int i)
bool EmptyMask(TInputIndexType &bIndex)
void computeAverageLocalCovariance(vnl_matrix< T2 > &resVariance, itk::VectorImage< T1, Dimension > *inputImage, itk::Image< unsigned char, Dimension > *maskImage, const itk::ImageRegion< Dimension > &averagingRegion, int localNeighborhood)
Noise estimation for a patch of a vector image.
LowMemoryNLMeansPatientToGroupComparisonBridge()
TInputImage::IndexType TInputIndexType