39#include "multi_array.hxx"
40#include "multi_convolution.hxx"
41#include "multi_labeling.hxx"
42#include "numerictraits.hxx"
43#include "accumulator.hxx"
44#include "array_vector.hxx"
112template <
unsigned int N,
class T,
class S1,
127 unsigned int label = 0;
129 end = iter.getEndIterator();
130 for(; iter != end; ++iter)
191 unsigned int sizeLimit;
196template <
unsigned int N,
class T,
class Label>
201 typedef MultiArrayView<N, T> DataImageType;
202 typedef MultiArrayView<N, Label> LabelImageType;
204 typedef typename PromoteTraits<
205 typename NormTraits<T>::NormType,
206 typename NormTraits<MultiArrayIndex>::NormType
207 >::Promote DistanceType;
209 Slic(DataImageType dataImage,
211 DistanceType intensityScaling,
213 SlicOptions
const & options = SlicOptions());
215 unsigned int execute();
218 void updateAssigments();
219 unsigned int postProcessing();
221 typedef MultiArray<N,DistanceType> DistanceImageType;
224 DataImageType dataImage_;
225 LabelImageType labelImage_;
226 DistanceImageType distance_;
228 DistanceType normalization_;
229 SlicOptions options_;
232 typedef acc::AccumulatorChainArray<CoupledArrays<N, T, Label>, Statistics> RegionFeatures;
233 RegionFeatures clusters_;
238template <
unsigned int N,
class T,
class Label>
239Slic<N, T, Label>::Slic(
240 DataImageType dataImage,
242 DistanceType intensityScaling,
244 SlicOptions
const & options)
245: shape_(dataImage.shape()),
246 dataImage_(dataImage),
249 max_radius_(maxRadius),
250 normalization_(sq(intensityScaling) / sq(max_radius_)),
253 clusters_.ignoreLabel(0);
256template <
unsigned int N,
class T,
class Label>
257unsigned int Slic<N, T, Label>::execute()
260 for(
size_t i=0;
i<options_.iter; ++
i)
270 return postProcessing();
273template <
unsigned int N,
class T,
class Label>
275Slic<N, T, Label>::updateAssigments()
278 distance_.init(NumericTraits<DistanceType>::max());
279 for(
unsigned int c=1; c<=clusters_.maxRegionLabel(); ++c)
284 typedef typename LookupTag<RegionCenter, RegionFeatures>::value_type
CenterType;
295 Iterator iter = createCoupledIterator(dataImage_, labelImage_, distance_).
297 end = iter.getEndIterator();
300 for(; iter !=
end; ++iter)
316template <
unsigned int N,
class T,
class Label>
318Slic<N, T, Label>::postProcessing()
324 unsigned int sizeLimit = options_.sizeLimit == 0
325 ? (
unsigned int)(0.25 * labelImage_.size() /
maxLabel)
326 : options_.sizeLimit;
335 typedef GridGraph<N, undirected_tag> Graph;
342 ArrayVector<unsigned char> done(
maxLabel+1,
false);
345 for (
graph_scanner node(graph); node != lemon::INVALID; ++node)
347 Label label = labelImage_[*node];
357 Label other = labelImage_[graph.target(*
arc)];
360 regions.makeUnion(label, other);
374 for (
graph_scanner node(graph); node != lemon::INVALID; ++node)
376 labelImage_[*node] = regions.findLabel(labelImage_[*node]);
460template <
unsigned int N,
class T,
class S1,
472 typedef typename NormTraits<T>::NormType
TmpType;
MultiArrayShape< actual_dimension >::type difference_type
Definition multi_array.hxx:739
Class for a single RGB value.
Definition rgbvalue.hxx:128
RGBValue()
Definition rgbvalue.hxx:209
void init(Iterator i, Iterator end)
Definition tinyvector.hxx:708
TinyVectorView< VALUETYPE, TO-FROM > subarray() const
Definition tinyvector.hxx:887
iterator end()
Definition tinyvector.hxx:864
bool any() const
Definition tinyvector.hxx:838
Class for fixed size vectors.
Definition tinyvector.hxx:1008
Coord< Mean > RegionCenter
Alias. Region center.
Definition accumulator-grammar.hxx:223
PowerSum< 0 > Count
Alias. Count.
Definition accumulator-grammar.hxx:166
DivideByCount< Sum > Mean
Alias. Mean.
Definition accumulator-grammar.hxx:173
void extractFeatures(...)
int floor(FixedPoint< IntBits, FracBits > v)
rounding down.
Definition fixedpoint.hxx:667
void gaussianGradientMagnitude(...)
Calculate the gradient magnitude by means of a 1st derivatives of Gaussian filter.
unsigned int slicSuperpixels(...)
Compute SLIC superpixels in arbitrary dimensions.
int round(FixedPoint< IntBits, FracBits > v)
rounding to the nearest integer.
Definition fixedpoint.hxx:683
unsigned int labelMultiArray(...)
Find the connected components of a MultiArray with arbitrary many dimensions.
unsigned int labelImage(...)
Find the connected components of a segmented image.
unsigned int generateSlicSeeds(...)
Generate seeds for SLIC superpixel computation in arbitrary dimensions.
@ DirectNeighborhood
use only direct neighbors
Definition multi_fwd.hxx:187
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition fftw3.hxx:1044
CoupledScanOrderIterator< HandleType::dimensions, HandleType > IteratorType
Definition multi_iterator_coupled.hxx:722
Options object for slicSuperpixels().
Definition slic.hxx:158
SlicOptions & minSize(unsigned int s)
Minimum superpixel size.
Definition slic.hxx:184
SlicOptions()
Create options object with default settings.
Definition slic.hxx:163
SlicOptions & iterations(unsigned int i)
Number of iterations.
Definition slic.hxx:172