File: ConnectedThreshold.cpp

package info (click to toggle)
freemat 4.2%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 142,116 kB
  • sloc: ansic: 126,788; cpp: 62,015; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 107
file content (39 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (2)
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
#include "ITKWrap.hpp"
#include <itkConnectedThresholdImageFilter.h>


template <int dims, DataClass dataclass, class PixelClass>
static Array ConnectedThresholdFilter(const ArrayVector & arg)
{
  if (arg.size() < 4) throw Exception("connectedthreshold filter requires at least four arguments");
  if (arg[1].rows() != dims) throw Exception("seedlist must be dims x N array of seed locations, where dims matches the dimensionality of the input image");
  typedef itk::Image<PixelClass, dims> ITKType;
  typename ITKType::Pointer imageIn = CreateITKFromArray<dims,dataclass,PixelClass>(arg[0]);
  typedef itk::ConnectedThresholdImageFilter<ITKType, ITKType> FilterType;
  typename FilterType::Pointer filter = FilterType::New();
  for (int i=0;i<arg[1].cols();i++)
    {
      typename ITKType::IndexType seed;
      for (int j=0;j<dims;j++)
	seed[j] = arg[1].get(i*dims + j + 1).asDouble() - 1;
      filter->AddSeed(seed);
    }
  filter->SetUpper(arg[3].asDouble());
  filter->SetLower(arg[2].asDouble());
  if (arg.size() > 4)
    filter->SetReplaceValue(arg[4].asDouble());
  filter->SetInput(imageIn);
  itk::Indent ndt;
  filter->PrintSelf(std::cout,ndt);
  filter->Update();
  return CreateArrayFromITK<dims,dataclass,PixelClass>(filter->GetOutput());
}

//@@Signature
//gfunction connectedthreshold ConnectedThresholdFunction
//input x seedlist low high replacevalue
//output y
ArrayVector ConnectedThresholdFunction(int nargout, const ArrayVector& arg)
{
  ITKCases(ConnectedThresholdFilter,arg);
}