-
Notifications
You must be signed in to change notification settings - Fork 1
/
vxlImgFilter.cxx
106 lines (86 loc) · 2.59 KB
/
vxlImgFilter.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* \file: vxlImgFilter.cxx
* \author: Sankhesh Jhaveri
* \brief: defines vxlImgFilter class
**/
#include "vxlImgFilter.h"
#include <vil/vil_load.h>
#include <vil/algo/vil_gauss_filter.h>
#include <vil/algo/vil_sobel_3x3.h>
#include <vil/algo/vil_suppress_non_max_edges.h>
#include <vil/vil_math.h>
#include <itkImageRegionIterator.h>
//Constructor
vxlImgFilter::vxlImgFilter() :
thresh1( 1.0f ),
thresh2( 1.0f ),
inputImage(),
internalImage()
{
}
void vxlImgFilter::setFilterInput(const vcl_string &filename)
{
this->inputImage = vil_load( filename.c_str(), false );
}
void vxlImgFilter::PerformFiltering( void )
{
vil_image_view< UTILS::ScalarPixelType > smoothIm, grad_i, grad_j;
vil_gauss_filter_5tap_params params( 1.0f );
vil_gauss_filter_5tap( this->inputImage, smoothIm, params );
vil_sobel_3x3( smoothIm, grad_i, grad_j);
vil_suppress_non_max_edges(grad_i, grad_j, (double)this->thresh1, this->internalImage);
UTILS::ScalarPixelType min, max;
vil_math_value_range( this->internalImage, min, max);
for (unsigned j = 0; j < this->internalImage.nj(); j++)
{
for( unsigned i = 0; i < this->internalImage.ni(); i++ )
{
this->internalImage(i,j) = (this->internalImage(i,j)-min)*255/(max-min);
if(this->internalImage(i,j) >= this->thresh2 )
this->internalImage(i,j) = 255;
else
this->internalImage(i,j) = 0;
}
}
}
UTILS::ScalarImageType::Pointer vxlImgFilter::ConvertVXLImgToITKImg( void )
{
UTILS::ScalarImageType::Pointer image = UTILS::ScalarImageType::New();
UTILS::ScalarImageType::SizeType size;
size[0] = this->internalImage.ni();
size[1] = this->internalImage.nj();
UTILS::ScalarImageType::IndexType start;
start[0] = 0;
start[1] = 0;
UTILS::ScalarImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
double spacing[2];
spacing[0] = 1;
spacing[1] = 1;
double origin[2];
origin[0] = 0;
origin[1] = 0;
image->SetRegions( region );
image->Allocate();
image->SetSpacing( spacing );
image->SetOrigin( origin );
typedef itk::ImageRegionIterator< UTILS::ScalarImageType > IteratorType;
IteratorType It( image, region );
It.GoToBegin();
vil_image_view< UTILS::ScalarPixelType >::const_iterator internalImageIterator;
internalImageIterator = this->internalImage.begin();
while( !It.IsAtEnd() )
{
It.Set( *internalImageIterator );
++It;
++internalImageIterator;
}
return image;
}
vtkSmartPointer<vtkImageActor> vxlImgFilter::getFilterOutput( void )
{
this->PerformFiltering();
UTILS::ScalarImageType::Pointer image = this->ConvertVXLImgToITKImg();
return UTILS::ITKToVTKConvert( UTILS::ComposeRGBImage( image ) );
}