aimsalgo 6.0.0
Neuroimaging image processing
curv3Diso.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34
35#ifndef AIMS_MATH_CURV3DISO_H
36#define AIMS_MATH_CURV3DISO_H
37
38#include <aims/math/mathelem.h>
39#include <cartodata/volume/volume.h>
40
48
49
52template <class T> inline
56
57
58template <class T>
62{
63 carto::VolumeRef<T> vol( rvol ); // convenience API
64 ASSERT(vol->getSizeT()==1);
65 carto::VolumeRef<float> curv( vol->getSizeX(), vol->getSizeY(),
66 vol->getSizeZ(), 1, vol->getBorders() );
67 curv.fillBorder(0);
68 curv = 0.0;
69 curv.setVoxelSize( vol->getVoxelSize() );
70 float fx,fy,fz,fxx,fyy,fzz,fxy,fxz,fyz;
71 std::vector<int> dim = vol->getSize();
72
73 switch (type)
74 {
76 for (int z=2;z<dim[2]-2;z++)
77 for (int y=2;y<dim[1]-2;y++)
78 for (int x=2;x<dim[0]-2;x++)
79 { if (vol(x-1,y,z)!=vol(x+1,y,z) ||
80 vol(x,y-1,z)!=vol(x,y+1,z) ||
81 vol(x,y,z-1)!=vol(x,y,z+1) )
82 { fx = ((float)vol(x+1,y,z) - (float)vol(x-1,y,z) ) / 2;
83 fy = ((float)vol(x,y+1,z) - (float)vol(x,y-1,z) ) / 2;
84 fz = ((float)vol(x,y,z+1) - (float)vol(x,y,z-1) ) / 2;
85 fxx = ((float)vol(x+2,y,z) - 2 * (float)vol(x,y,z) +
86 (float)vol(x-2,y,z) ) / 4;
87 fyy = ((float)vol(x,y+2,z) - 2 * (float)vol(x,y,z) +
88 (float)vol(x,y-2,z) ) / 4;
89 fzz = ((float)vol(x,y,z+2) - 2 * (float)vol(x,y,z) +
90 (float)vol(x,y,z-2) ) / 4;
91 fxy = ((float)vol(x+1,y+1,z) -
92 (float)vol(x-1,y+1,z) -
93 (float)vol(x+1,y-1,z) +
94 (float)vol(x-1,y-1,z) ) / 4;
95 fxz = ((float)vol(x+1,y,z+1) -
96 (float)vol(x-1,y,z+1) -
97 (float)vol(x+1,y,z-1) +
98 (float)vol(x-1,y,z-1) ) / 4;
99 fyz = ((float)vol(x,y+1,z+1) -
100 (float)vol(x,y-1,z+1) -
101 (float)vol(x,y+1,z-1) +
102 (float)vol(x,y-1,z-1) ) / 4;
103 curv(x,y,z) = ( fx*fx*(fyy*fzz-fyz*fyz) +
104 2*fy*fz*(fxz*fxy-fxx*fyz) +
105 fy*fy*(fxx*fzz-fxz*fxz) +
106 2*fx*fz*(fyz*fxy-fyy*fxz) +
107 fz*fz*(fxx*fyy-fxy*fxy) +
108 2*fx*fy*(fxz*fyz-fzz*fxy) ) /
109 ((fx*fx+fy*fy+fz*fz)*(fx*fx+fy*fy+fz*fz));
110 }
111 else curv(x,y,z) = 0;
112 }
113 break;
115 for (int z=2;z<dim[2]-2;z++)
116 for (int y=2;y<dim[1]-2;y++)
117 for (int x=2;x<dim[0]-2;x++)
118 { if (vol(x-1,y,z)!=vol(x+1,y,z) ||
119 vol(x,y-1,z)!=vol(x,y+1,z) ||
120 vol(x,y,z-1)!=vol(x,y,z+1) )
121 { fx = ((float)vol(x+1,y,z) - (float)vol(x-1,y,z) ) / 2;
122 fy = ((float)vol(x,y+1,z) - (float)vol(x,y-1,z) ) / 2;
123 fz = ((float)vol(x,y,z+1) - (float)vol(x,y,z-1) ) / 2;
124 fxx = ((float)vol(x+2,y,z) - 2 * (float)vol(x,y,z) +
125 (float)vol(x-2,y,z) ) / 4;
126 fyy = ((float)vol(x,y+2,z) - 2 * (float)vol(x,y,z) +
127 (float)vol(x,y-2,z) ) / 4;
128 fzz = ((float)vol(x,y,z+2) - 2 * (float)vol(x,y,z) +
129 (float)vol(x,y,z-2) ) / 4;
130 fxy = ((float)vol(x+1,y+1,z) -
131 (float)vol(x-1,y+1,z) -
132 (float)vol(x+1,y-1,z) +
133 (float)vol(x-1,y-1,z) ) / 4;
134 fxz = ((float)vol(x+1,y,z+1) -
135 (float)vol(x-1,y,z+1) -
136 (float)vol(x+1,y,z-1) +
137 (float)vol(x-1,y,z-1) ) / 4;
138 fyz = ((float)vol(x,y+1,z+1) -
139 (float)vol(x,y-1,z+1) -
140 (float)vol(x,y+1,z-1) +
141 (float)vol(x,y-1,z-1) ) / 4;
142 curv(x,y,z) = ( fx*fx*(fyy+fzz) - 2*fy*fz*fyz +
143 fy*fy*(fxx+fzz) - 2*fx*fz*fxz +
144 fz*fz*(fxx+fyy) - 2*fx*fy*fxy ) /
145 ( 2 * cube( sqrt(fx*fx + fy*fy + fz*fz) ) );
146 }
147 else curv(x,y,z) = 0;
148 }
149 break;
150 }
151 return curv;
152}
153
154
155#endif
#define ASSERT(EX)
int getSizeZ() const
std::vector< int > getBorders() const
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
std::vector< float > getVoxelSize() const
void fillBorder(const T &value)
int getSizeT() const
std::vector< int > getSize() const
int getSizeY() const
int getSizeX() const
AimsCurvatureType
The different 3D curvature types.
Definition curv3Diso.h:44
@ AIMS_GAUSSIAN_CURVATURE
Definition curv3Diso.h:45
@ AIMS_MEAN_CURVATURE
Definition curv3Diso.h:46
carto::VolumeRef< float > AimsIsoIntensityCurvature3D(const carto::rc_ptr< carto::Volume< T > > &vol, AimsCurvatureType type=AIMS_MEAN_CURVATURE)
3D curvature functions on an intensity image f(x,y,z) = I
Definition curv3Diso.h:60
T cube(const T &val)