-
Notifications
You must be signed in to change notification settings - Fork 2
/
cthresholdobject.cpp
56 lines (46 loc) · 1.46 KB
/
cthresholdobject.cpp
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
#include "cthresholdobject.h"
CThresholdObject::CThresholdObject() :
nLevels(1)
{
}
CThresholdObject::~CThresholdObject()
{
}
void CThresholdObject::SetOutput( ThresholdImageType::Pointer cImage)
{
m_OutputImage = nullptr;
/** Convert Threshold Image Type to Output Image Type **/
using CastFilterType = itk::CastImageFilter<ThresholdImageType, OutputImageType>;
auto caster = CastFilterType::New();
caster->SetInput(cImage);
try
{
caster->Update();
}
catch (itk::ExceptionObject &excp)
{
std::cerr << "Error--> (" << __FILE__ << ":" << __LINE__ << ")" << std::endl;
std::cerr << "Rescale Image to Output Type Failed: " << excp << std::endl;
return;
}
m_OutputImage = caster->GetOutput();
}
void CThresholdObject::SetRGBOutput (ThresholdImageType::Pointer cImage)
{
m_RGBOutputImage = nullptr;
/** Map ThresholdLabels to distinct RGB Colors **/
using LabelRGBFilterType = itk::LabelToRGBImageFilter<ThresholdImageType, RGBImageType>;
auto colormapImageFilter = LabelRGBFilterType::New();
colormapImageFilter->SetInput(cImage);
try
{
colormapImageFilter->Update();
}
catch (itk::ExceptionObject &excp)
{
std::cerr << "Error--> (" << __FILE__ << ":" << __LINE__ << ")" << std::endl;
std::cerr << "RGB Conversion Failed: " << excp << std::endl;
return;
}
m_RGBOutputImage = colormapImageFilter->GetOutput();
}