aimstil  5.0.5
SubImageExtractor.h
Go to the documentation of this file.
1 #ifndef TIL_SUBIMAGEEXTRACTOR_H
2 #define TIL_SUBIMAGEEXTRACTOR_H
3 
4 
5 // Standard library includes
6 
7 #include <iostream>
8 
9 
10 // Local includes
11 
12 #include "til/til_common.h"
13 
14 #include "til/Range.h"
15 #include "til/imageTools.h"
16 #include "til/miscTools.h"
17 
18 
19 // Extract a sub-image out of an original image
20 // If the crop box is out of the image range, the image is extrapolated
21 
22 
23 // Namespace
24 
25 namespace til {
26 
27 
28 template <class Extrapolator, class TImageIn, class TImageOut>
29 void extractSubImage(const TImageIn & im,
30  TImageOut & subIm,
31  const Range<int,3> & cropbox)
32 {
33  typedef typename TImageIn::value_type TPixelIn;
34  typedef typename TImageOut::value_type TPixelOut;
35 
36  // Check whether input image is allocated
37  allocationCheck(im);
38 
39  // Allocate output image
40  subIm.init(cropbox.dims(), im.vdim());
41  /*
42  cropbox.getSizeX(),
43  cropbox.getSizeY(),
44  cropbox.getSizeZ(),
45  im.vdim()[0],
46  im.vdim()[1],
47  im.vdim()[2]);
48  */
49 
50  // set origin of subimage
51  //subIm.setOrigin(im.getOrigin() - cropbox.min_bounds());
52 
53  typename Iterator<TImageOut>::Linear iSubIm(subIm);
54 
55  // extract sub image
57  for (p[2] = cropbox.min_bounds()[2]; p[2] <= cropbox.max_bounds()[2]; ++p[2])
58  {
59  for (p[1] = cropbox.min_bounds()[1]; p[1] <= cropbox.max_bounds()[1]; ++p[1])
60  {
61  for (p[0] = cropbox.min_bounds()[0]; p[0] <= cropbox.max_bounds()[0]; ++p[0])
62  {
63  *iSubIm = castValue<TPixelIn, TPixelOut>(Extrapolator::getValue(im, p));
64  /*
65  if (contains(im, i, j, k))
66  {
67  *iSubIm = castValue<TPixelIn, TPixelOut>(im.getValue(i,j,k));
68  }
69  else
70  {
71  *iSubIm = castValue<TPixelIn, TPixelOut>(Extrapolator::getExtrapolatedValue((const TImageIn*)im, i, j, k));
72  }
73  */
74  ++iSubIm;
75  }
76  }
77  }
78 }
79 
80 } // namespace
81 
82 
83 #endif
84 
A trait class to assign iterators to image types.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
Small miscellaneous utility functions for images.
const numeric_array< T, D > & min_bounds() const
Get min bounds.
Definition: Box.h:41
const numeric_array< T, D > & max_bounds() const
Get max bounds.
Definition: Box.h:43
INLINE void allocationCheck(const TImage &im)
Check whether smart pointer and image are allocated.
Definition: imageTools.h:42
numeric_array< T, D > dims() const
Get range size.
Definition: Range.h:101
void extractSubImage(const TImageIn &im, TImageOut &subIm, const Range< int, 3 > &cropbox)