1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
16 #ifndef _itkProjectionFilter_txx
17 #define _itkProjectionFilter_txx
19 #include "itkProjectionFilter.h"
21 #include "mitkProgressBar.h"
22 //#include <itkSignedMaurerDistanceMapImageFilter.h>
24 #define SEARCHSIGMA 10 /* length in linear voxel dimensions */
25 #define MAXSEARCHLENGTH (3*SEARCHSIGMA)
32 ProjectionFilter::ProjectionFilter()
37 ProjectionFilter::~ProjectionFilter()
43 void ProjectionFilter::Project()
45 // Contains only code for the projection of FA data. The original FSL code contains some extra lines
46 // For projection of other measurements than FA
48 mitk::ProgressBar::GetInstance()->AddStepsToDo( 3 );
50 Float4DImageType::Pointer data_4d_projected = Float4DImageType::New();
51 data_4d_projected->SetRegions(m_AllFA->GetRequestedRegion());
52 data_4d_projected->SetDirection(m_AllFA->GetDirection());
53 data_4d_projected->SetSpacing(m_AllFA->GetSpacing());
54 data_4d_projected->SetOrigin(m_AllFA->GetOrigin());
55 data_4d_projected->Allocate();
56 data_4d_projected->FillBuffer(0.0);
58 Float4DImageType::SizeType size = m_AllFA->GetRequestedRegion().GetSize();
59 long s0 = size[0], s1 = size[1], s2 = size[2], s3 = size[3];
61 for(int t=0; t<s3; t++)
63 for(int z=1; z<s2-1; z++)
65 for(int y=1; y<s1-1; y++)
68 for(int x=1; x<s0-1; x++)
71 VectorImageType::IndexType ix;
72 ix[0] = x; ix[1] = y; ix[2] = z;
74 if(m_Skeleton->GetPixel(ix) != 0)
76 VectorImageType::PixelType dir = m_Directions->GetPixel(ix);
78 Float4DImageType::IndexType ix4d;
79 ix4d[0]=x; ix4d[1]=y; ix4d[2]=z; ix4d[3]=t;
80 float maxval = m_AllFA->GetPixel(ix4d);
81 float maxval_weighted = maxval;
82 float exponentfactor = -0.5 * (dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]) / (float)(SEARCHSIGMA*SEARCHSIGMA);
85 // No tubular structure here
86 if(m_Tube->GetPixel(ix) == 0)
88 for(int iters=0;iters<2;iters++)
92 for(int d=1;d<MAXSEARCHLENGTH;d++)
97 FloatImageType::IndexType ix3d;
98 int dx = x+dir[0]*D, dy = y+dir[1]*D, dz = z+dir[2]*D;
99 ix3d[0] = dx; ix3d[1] = dy; ix3d[2] = dz;
101 if(dx<0 || dy<0 || dz<0
102 || (dx>=s0 && dy<=s1 && dz<=s2))
106 else if(m_DistanceMap->GetPixel(ix3d)>=distance)
108 float distanceweight = exp(d * d * exponentfactor);
109 distance = m_DistanceMap->GetPixel(ix3d);
111 ix4d[0]=x+dir[0]*D; ix4d[1]=y+dir[1]*D; ix4d[2]=z+dir[2]*D; ix4d[3]=t;
113 if(distanceweight*m_AllFA->GetPixel(ix4d)>maxval_weighted)
115 maxval = m_AllFA->GetPixel(ix4d);
116 maxval_weighted = maxval*distanceweight;
133 for(int dy=-MAXSEARCHLENGTH; dy<=MAXSEARCHLENGTH;dy++) {
134 for(int dx=-MAXSEARCHLENGTH; dx<=MAXSEARCHLENGTH; dx++) {
136 float distanceweight = exp(-0.5 * (dx*dx+dy*dy) / (float)(SEARCHSIGMA*SEARCHSIGMA) );
137 float r=sqrt((float)(dx*dx+dy*dy));
143 for(float rr=1; rr<=r+0.1; rr++) /* search outwards from centre to current voxel - test that distancemap always increasing */
146 int dx1=round(rr*dx/r);
147 int dy1=round(rr*dy/r);
148 int dx2=round((rr+1)*dx/r);
149 int dy2=round((rr+1)*dy/r);
151 RealImageType::IndexType ix1, ix2;
152 ix1[0]=x+dx1; ix1[1]=y+dy1; ix1[2]=z;
153 ix2[0]=x+dx2; ix2[1]=y+dy2; ix2[2]=z;
154 if(m_DistanceMap->GetPixel(ix1) > m_DistanceMap->GetPixel(ix2) )
161 ix4d[0]=x+dx; ix4d[1]=y+dy, ix4d[2]=z; ix4d[3]=t;
162 if( allok && (distanceweight * m_AllFA->GetPixel(ix4d) > maxval_weighted) )
164 maxval = m_AllFA->GetPixel(ix4d);
165 maxval_weighted = maxval * distanceweight;
175 ix4d[0]=x; ix4d[1]=y; ix4d[2]=z; ix4d[3]=t;
177 data_4d_projected->SetPixel(ix4d, maxval);
185 m_Projections = data_4d_projected;
196 #endif // _itkProjectionFilter_txx