Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkProjectionFilter.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #ifndef _itkProjectionFilter_txx
17 #define _itkProjectionFilter_txx
18 
19 #include "itkProjectionFilter.h"
20 
21 #include "mitkProgressBar.h"
22 //#include <itkSignedMaurerDistanceMapImageFilter.h>
23 
24 #define SEARCHSIGMA 10 /* length in linear voxel dimensions */
25 #define MAXSEARCHLENGTH (3*SEARCHSIGMA)
26 
27 
28 namespace itk
29 {
30 
31 
32  ProjectionFilter::ProjectionFilter()
33  {
34 
35  }
36 
37  ProjectionFilter::~ProjectionFilter()
38  {
39 
40 
41  }
42 
43  void ProjectionFilter::Project()
44  {
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
47 
48  mitk::ProgressBar::GetInstance()->AddStepsToDo( 3 );
49 
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);
57 
58  Float4DImageType::SizeType size = m_AllFA->GetRequestedRegion().GetSize();
59  long s0 = size[0], s1 = size[1], s2 = size[2], s3 = size[3];
60 
61  for(int t=0; t<s3; t++)
62  {
63  for(int z=1; z<s2-1; z++)
64  {
65  for(int y=1; y<s1-1; y++)
66  {
67 
68  for(int x=1; x<s0-1; x++)
69  {
70 
71  VectorImageType::IndexType ix;
72  ix[0] = x; ix[1] = y; ix[2] = z;
73 
74  if(m_Skeleton->GetPixel(ix) != 0)
75  {
76  VectorImageType::PixelType dir = m_Directions->GetPixel(ix);
77 
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);
83 
84 
85  // No tubular structure here
86  if(m_Tube->GetPixel(ix) == 0)
87  {
88  for(int iters=0;iters<2;iters++)
89  {
90  float distance=0;
91 
92  for(int d=1;d<MAXSEARCHLENGTH;d++)
93  {
94  int D=d;
95  if (iters==1) D=-d;
96 
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;
100 
101  if(dx<0 || dy<0 || dz<0
102  || (dx>=s0 && dy<=s1 && dz<=s2))
103  {
104  d=MAXSEARCHLENGTH;
105  }
106  else if(m_DistanceMap->GetPixel(ix3d)>=distance)
107  {
108  float distanceweight = exp(d * d * exponentfactor);
109  distance = m_DistanceMap->GetPixel(ix3d);
110 
111  ix4d[0]=x+dir[0]*D; ix4d[1]=y+dir[1]*D; ix4d[2]=z+dir[2]*D; ix4d[3]=t;
112 
113  if(distanceweight*m_AllFA->GetPixel(ix4d)>maxval_weighted)
114  {
115  maxval = m_AllFA->GetPixel(ix4d);
116  maxval_weighted = maxval*distanceweight;
117  }
118  }
119  else{
120  d=MAXSEARCHLENGTH;
121  }
122 
123 
124 
125  }
126 
127  }
128  }
129 
130  // Tubular structure
131  else
132  {
133  for(int dy=-MAXSEARCHLENGTH; dy<=MAXSEARCHLENGTH;dy++) {
134  for(int dx=-MAXSEARCHLENGTH; dx<=MAXSEARCHLENGTH; dx++) {
135 
136  float distanceweight = exp(-0.5 * (dx*dx+dy*dy) / (float)(SEARCHSIGMA*SEARCHSIGMA) );
137  float r=sqrt((float)(dx*dx+dy*dy));
138 
139  if (r>0)
140  {
141  int allok=1;
142 
143  for(float rr=1; rr<=r+0.1; rr++) /* search outwards from centre to current voxel - test that distancemap always increasing */
144  {
145 
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);
150 
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) )
155  {
156  allok=0;
157  }
158 
159  }
160 
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) )
163  {
164  maxval = m_AllFA->GetPixel(ix4d);
165  maxval_weighted = maxval * distanceweight;
166  }
167 
168 
169  }
170 
171  }
172  }
173  }
174 
175  ix4d[0]=x; ix4d[1]=y; ix4d[2]=z; ix4d[3]=t;
176 
177  data_4d_projected->SetPixel(ix4d, maxval);
178 
179  }
180  }
181  }
182  }
183  }
184 
185  m_Projections = data_4d_projected;
186 
187 
188 
189  }
190 
191 
192 
193 
194 
195 }
196 #endif // _itkProjectionFilter_txx