Skip to content

Commit 0ca3a0f

Browse files
committed
Add ITK version
1 parent f8725fe commit 0ca3a0f

File tree

7 files changed

+306
-2
lines changed

7 files changed

+306
-2
lines changed

DM.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*=========================================================================
2+
*
3+
* Curvature Filter
4+
*
5+
**************************************************************************
6+
7+
@phdthesis{gong:phd,
8+
title={Spectrally regularized surfaces},
9+
author={Gong, Yuanhao},
10+
year={2015},
11+
school={ETH Zurich, Nr. 22616},
12+
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
14+
*=========================================================================*/
15+
116
//Dual Mesh sctructure
217
class DM
318
{

ITK/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
set(CMAKE_CONFIGURATION_TYPES Release)
3+
project( CF )
4+
find_package( ITK REQUIRED )
5+
include( ${ITK_USE_FILE} )
6+
add_executable( CF main.cxx )
7+
target_link_libraries( CF ${ITK_LIBRARIES} )
8+
set(CMAKE_BUILD_TYPE Release)

ITK/itkCurvatureFilter.h

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*=========================================================================
2+
*
3+
* Curvature Filter in ITK, please cite following work in you paper!
4+
*
5+
**************************************************************************
6+
7+
@phdthesis{gong:phd,
8+
title={Spectrally regularized surfaces},
9+
author={Gong, Yuanhao},
10+
year={2015},
11+
school={ETH Zurich, Nr. 22616},
12+
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
14+
*=========================================================================*/
15+
//estimate the d_m by different curvature filters
16+
float GC(float & cur, float & pre, float & rigUp, float & right, float & rigDn, float & next, float & lefDn, float & left, float & lefUp);
17+
float MC(float & cur, float & pre, float & rigUp, float & right, float & rigDn, float & next, float & lefDn, float & left, float & lefUp);
18+
float TV(float & cur, float & pre, float & rigUp, float & right, float & rigDn, float & next, float & lefDn, float & left, float & lefUp);
19+
float (*projection)(float & cur, float & pre, float & rigUp, float & right, float & rigDn, float & next, float & lefDn, float & left, float & lefUp);
20+
void CurvatureFilter(itk::Image< float, 2 >::Pointer image, int FilterType, int IterationNumber)
21+
{
22+
23+
if (FilterType == 0) {projection = TV; std::cout<<"TV filter: with "<<IterationNumber<<" Iterations";}
24+
if (FilterType == 1) {projection = MC; std::cout<<"MC filter: with "<<IterationNumber<<" Iterations";}
25+
if (FilterType == 2) {projection = GC; std::cout<<"GC filter: with "<<IterationNumber<<" Iterations";}
26+
float d, cur;
27+
//image size and neighbor index
28+
itk::Image< float, 2 >::SizeType size = image->GetLargestPossibleRegion().GetSize();
29+
itk::Image< float, 2 >::IndexType index_cur, index_prev, index_rigUp, index_right, index_rigDn, index_next, index_leftDn, index_left, index_leftUp;
30+
31+
clock_t Tstart, Tend;
32+
Tstart = clock();
33+
34+
for(int it = 0; it < IterationNumber; ++it)
35+
{
36+
//domain decomposition, four sets
37+
for (int i = 1; i < size[0]; ++i, ++i)
38+
for (int j = 1; j < size[1]; ++j, ++j)
39+
{
40+
index_leftUp[0] = j-1, index_leftUp[1] = i-1, index_prev[0] = j, index_prev[1] = i-1, index_rigUp[0]=j+1, index_rigUp[1] = i-1;
41+
index_left[0]=j-1, index_left[1]=i, index_cur[0] = j, index_cur[1] = i, index_right[0]=j+1, index_right[1]=i;
42+
index_leftDn[0]=j-1, index_leftDn[1]=i+1, index_next[0]=j, index_next[1] = i+1, index_rigDn[0]=j+1, index_rigDn[1] = i+1;
43+
44+
cur = image->GetPixel(index_cur);
45+
d = (*projection)(cur, image->GetPixel(index_prev), image->GetPixel(index_rigUp), image->GetPixel(index_right), image->GetPixel(index_rigDn), image->GetPixel(index_next), image->GetPixel(index_leftDn), image->GetPixel(index_left), image->GetPixel(index_leftUp));
46+
image->SetPixel(index_cur, cur + d);
47+
}
48+
for (int i = 2; i < size[0]; ++i, ++i)
49+
for (int j = 2; j < size[1]; ++j, ++j)
50+
{
51+
index_leftUp[0] = j-1, index_leftUp[1] = i-1, index_prev[0] = j, index_prev[1] = i-1, index_rigUp[0]=j+1, index_rigUp[1] = i-1;
52+
index_left[0]=j-1, index_left[1]=i, index_cur[0] = j, index_cur[1] = i, index_right[0]=j+1, index_right[1]=i;
53+
index_leftDn[0]=j-1, index_leftDn[1]=i+1, index_next[0]=j, index_next[1] = i+1, index_rigDn[0]=j+1, index_rigDn[1] = i+1;
54+
55+
cur = image->GetPixel(index_cur);
56+
d = (*projection)(cur, image->GetPixel(index_prev), image->GetPixel(index_rigUp), image->GetPixel(index_right), image->GetPixel(index_rigDn), image->GetPixel(index_next), image->GetPixel(index_leftDn), image->GetPixel(index_left), image->GetPixel(index_leftUp));
57+
image->SetPixel(index_cur, cur + d);
58+
}
59+
for (int i = 1; i < size[0]; ++i, ++i)
60+
for (int j = 2; j < size[1]; ++j, ++j)
61+
{
62+
index_leftUp[0] = j-1, index_leftUp[1] = i-1, index_prev[0] = j, index_prev[1] = i-1, index_rigUp[0]=j+1, index_rigUp[1] = i-1;
63+
index_left[0]=j-1, index_left[1]=i, index_cur[0] = j, index_cur[1] = i, index_right[0]=j+1, index_right[1]=i;
64+
index_leftDn[0]=j-1, index_leftDn[1]=i+1, index_next[0]=j, index_next[1] = i+1, index_rigDn[0]=j+1, index_rigDn[1] = i+1;
65+
66+
cur = image->GetPixel(index_cur);
67+
d = (*projection)(cur, image->GetPixel(index_prev), image->GetPixel(index_rigUp), image->GetPixel(index_right), image->GetPixel(index_rigDn), image->GetPixel(index_next), image->GetPixel(index_leftDn), image->GetPixel(index_left), image->GetPixel(index_leftUp));
68+
image->SetPixel(index_cur, cur + d);
69+
}
70+
for (int i = 2; i < size[0]; ++i, ++i)
71+
for (int j = 1; j < size[1]; ++j, ++j)
72+
{
73+
index_leftUp[0] = j-1, index_leftUp[1] = i-1, index_prev[0] = j, index_prev[1] = i-1, index_rigUp[0]=j+1, index_rigUp[1] = i-1;
74+
index_left[0]=j-1, index_left[1]=i, index_cur[0] = j, index_cur[1] = i, index_right[0]=j+1, index_right[1]=i;
75+
index_leftDn[0]=j-1, index_leftDn[1]=i+1, index_next[0]=j, index_next[1] = i+1, index_rigDn[0]=j+1, index_rigDn[1] = i+1;
76+
77+
cur = image->GetPixel(index_cur);
78+
d = (*projection)(cur, image->GetPixel(index_prev), image->GetPixel(index_rigUp), image->GetPixel(index_right), image->GetPixel(index_rigDn), image->GetPixel(index_next), image->GetPixel(index_leftDn), image->GetPixel(index_left), image->GetPixel(index_leftUp));
79+
image->SetPixel(index_cur, cur + d);
80+
}
81+
}
82+
83+
Tend = clock() - Tstart;
84+
double time = double(Tend)/(CLOCKS_PER_SEC/1000.0);
85+
std::cout<<" running time is "<<time<<" milliseconds"<<std::endl;
86+
}
87+
88+
// *************************** functions ********************************************
89+
//estimate d_m (minimal projection signed distance)
90+
float GC(float & cur, float & prev, float & rigUp, float & right, float & rigDn, float & down, float & lefDn, float & left, float& lefUp)
91+
{
92+
float d_m = (prev + down)/2 - cur;
93+
float tmp = (left, right)/2 - cur;
94+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
95+
tmp = (lefUp, rigDn)/2 - cur;
96+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
97+
tmp = (lefDn, rigUp)/2 - cur;
98+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
99+
100+
//hybrid
101+
tmp = (left + lefUp + prev)/3 - cur;
102+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
103+
tmp = (prev + rigUp + right)/3 - cur;
104+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
105+
tmp = (right + rigDn + down)/3 - cur;
106+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
107+
tmp = (down + lefDn + left)/3 - cur;
108+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
109+
110+
return d_m;
111+
}
112+
float MC(float & cur, float & prev, float & rigUp, float & right, float & rigDn, float & down, float & lefDn, float & left, float& lefUp)
113+
{
114+
float TM = 8*cur;
115+
116+
float d_m = (prev + down)*2.5f - rigUp - rigDn + 5*right - TM;
117+
float tmp = (prev + down)*2.5f - lefUp - lefDn + 5*left - TM;
118+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
119+
tmp = (left + right)*2.5f - lefUp - rigUp + 5*prev - TM;
120+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
121+
tmp = (left + right)*2.5f - lefDn - rigDn + 5*down - TM;
122+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
123+
124+
return d_m/8;
125+
}
126+
float TV(float & cur, float & prev, float & rigUp, float & right, float & rigDn, float & down, float & lefDn, float & left, float& lefUp)
127+
{
128+
float TM = 5*cur;
129+
130+
float d_m = prev + down + lefUp + left + lefDn - TM;
131+
float tmp = prev + down + rigUp + rigDn + right - TM;
132+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
133+
tmp = left + lefUp + prev + rigUp + right - TM;
134+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
135+
tmp = left + lefDn + down + rigDn + right - TM;
136+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
137+
138+
//diag
139+
tmp = lefUp + prev + rigUp + left + lefDn - TM;
140+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
141+
tmp = lefUp + prev + rigUp + right + rigDn - TM;
142+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
143+
tmp = lefDn + down + rigDn + left + lefUp - TM;
144+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
145+
tmp = lefDn + down + rigDn + right + rigUp - TM;
146+
if (fabs(tmp) < fabs(d_m)) d_m = tmp;
147+
148+
return d_m/5;
149+
}
150+

ITK/main.cxx

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*=========================================================================
2+
*
3+
* Curvature Filter in ITK, please cite following work in you paper!
4+
*
5+
**************************************************************************
6+
7+
@phdthesis{gong:phd,
8+
title={Spectrally regularized surfaces},
9+
author={Gong, Yuanhao},
10+
year={2015},
11+
school={ETH Zurich, Nr. 22616},
12+
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
14+
*=========================================================================*/
15+
16+
#include "itkImageFileReader.h"
17+
#include "itkImageFileWriter.h"
18+
#include "itkRescaleIntensityImageFilter.h"
19+
20+
#include "itkConstNeighborhoodIterator.h"
21+
#include "itkImageRegionIterator.h"
22+
#include <time.h>
23+
#include "itkCurvatureFilter.h"
24+
25+
int FType = 2;
26+
27+
int main( int argc, char * argv[] )
28+
{
29+
if( argc < 5 )
30+
{
31+
std::cerr << "Usage: " << std::endl;
32+
std::cerr << argv[0] << " inputImageFile outputImageFile filterType numberOfIterations" << std::endl;
33+
return EXIT_FAILURE;
34+
}
35+
36+
const unsigned int numberOfIterations = atoi( argv[4] );
37+
const char * filterType = argv[3];
38+
39+
if (*filterType == 't') {FType = 0; }
40+
if (*filterType == 'm') {FType = 1; }
41+
if (*filterType == 'g') {FType = 2; }
42+
43+
// read image
44+
typedef float PixelType;
45+
typedef itk::Image< PixelType, 2 > ImageType;
46+
typedef itk::ImageFileReader< ImageType > ReaderType;
47+
48+
typedef itk::ConstNeighborhoodIterator< ImageType > NeighborhoodIteratorType;
49+
typedef itk::ImageRegionIterator< ImageType> IteratorType;
50+
51+
ReaderType::Pointer reader = ReaderType::New();
52+
reader->SetFileName( argv[1] );
53+
try
54+
{
55+
reader->Update();
56+
}
57+
catch ( itk::ExceptionObject &err)
58+
{
59+
std::cout << "ExceptionObject caught !" << std::endl;
60+
std::cout << err << std::endl;
61+
return -1;
62+
}
63+
ImageType::Pointer image = reader->GetOutput();
64+
65+
/*********** curvature filter ******************/
66+
CurvatureFilter(image, FType, numberOfIterations);
67+
/*********** curvature filter ******************/
68+
69+
// save the result
70+
typedef unsigned char WritePixelType;
71+
typedef itk::Image< WritePixelType, 2 > WriteImageType;
72+
typedef itk::ImageFileWriter< WriteImageType > WriterType;
73+
74+
typedef itk::RescaleIntensityImageFilter<
75+
ImageType, WriteImageType > RescaleFilterType;
76+
77+
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
78+
79+
rescaler->SetOutputMinimum( 0 );
80+
rescaler->SetOutputMaximum( 255 );
81+
rescaler->SetInput(image);
82+
83+
WriterType::Pointer writer = WriterType::New();
84+
writer->SetFileName( argv[2] );
85+
writer->SetInput(rescaler->GetOutput());
86+
try
87+
{
88+
writer->Update();
89+
}
90+
catch ( itk::ExceptionObject &err)
91+
{
92+
std::cout << "ExceptionObject caught !" << std::endl;
93+
std::cout << err << std::endl;
94+
return -1;
95+
}
96+
97+
return EXIT_SUCCESS;
98+
}
99+

ReadMe.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ This code was developed by Yuanhao Gong during his PhD at MOSAIC Group.
33
Please cite Yuanhao's PhD thesis if you use this code in your work. Thank you!
44

55
=============================================================
6+
67
@phdthesis{gong:phd,
78
title={Spectrally regularized surfaces},
89
author={Gong, Yuanhao},
910
year={2015},
1011
school={ETH Zurich, Nr. 22616},
1112
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
1214
=============================================================
1315

1416
FAQ:

main.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*=========================================================================
2+
*
3+
* Curvature Filter
4+
*
5+
**************************************************************************
6+
7+
@phdthesis{gong:phd,
8+
title={Spectrally regularized surfaces},
9+
author={Gong, Yuanhao},
10+
year={2015},
11+
school={ETH Zurich, Nr. 22616},
12+
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
14+
*=========================================================================*/
15+
116
#include <opencv2/core/core.hpp>
217
#include <opencv2/highgui/highgui.hpp>
318
#include <opencv2/imgproc/imgproc.hpp>
@@ -71,8 +86,8 @@ int main(int argc, char** argv)
7186

7287
if (argc==6)
7388
{
74-
//filter solver for the variational models
75-
DualMesh.read(argv[1]);
89+
//filter solver for the variational models
90+
DualMesh.read(argv[1]);
7691
DualMesh.Solver(Type, mytime, ItNum, lambda, DataFitOrder);
7792
cout<<"runtime is "<<mytime<<" milliseconds."<<endl;
7893
DualMesh.write("CF_Solver.png");

main_MultiScale.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*=========================================================================
2+
*
3+
* Curvature Filter
4+
*
5+
**************************************************************************
6+
7+
@phdthesis{gong:phd,
8+
title={Spectrally regularized surfaces},
9+
author={Gong, Yuanhao},
10+
year={2015},
11+
school={ETH Zurich, Nr. 22616},
12+
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
13+
14+
*=========================================================================*/
15+
116
#include <opencv2/core/core.hpp>
217
#include <opencv2/highgui/highgui.hpp>
318
#include <opencv2/imgproc/imgproc.hpp>

0 commit comments

Comments
 (0)