vil_abs_shuffle_distance.h
Go to the documentation of this file.
1 #ifndef vil_abs_shuffle_distance_h_
2 #define vil_abs_shuffle_distance_h_
3 //:
4 // \file
5 // \brief Compute shuffle distance between two images
6 // \author Tim Cootes
7 
9 #include <vil/vil_image_view.h>
10 
11 //: Return minimum value of |im[offset[k]]-v0| k=0..n-1
12 template <class T1, class T2>
13 inline double vil_abs_shuffle_distance(T1 v0, const T2* im,
14  const std::ptrdiff_t* offset, unsigned n)
15 {
16  double min_v = im[offset[0]]<v0?(v0-im[offset[0]]):(im[offset[0]]-v0);
17  for (unsigned i=1;i<n;++i)
18  {
19  T2 v1 = im[offset[i]];
20  double abs_diff = (v0<v1?(v1-v0):(v0-v1));
21  if (abs_diff<min_v) min_v=abs_diff;
22  }
23  return min_v;
24 }
25 
26 //: Return min difference of pixels under structuring element centred at (i0,j0)
27 // I.e., returns minimum of |v0-image(i,j,plane)| over (i,j) in element.
28 // Checks boundary overlap.
29 // \relatesalso vil_image_view
30 // \relatesalso vil_structuring_element
31 template <class T1, class T2>
32 inline double vil_abs_shuffle_distance(T1 v0, const vil_image_view<T2>& image,
33  unsigned plane,
34  const vil_structuring_element& element,
35  int i0, int j0)
36 {
37  double min_v=9e99;
38  unsigned n = element.p_i().size();
39  for (unsigned int k=0;k<n;++k)
40  {
41  unsigned int i = i0+element.p_i()[k];
42  unsigned int j = j0+element.p_j()[k];
43  if (i<image.ni() && j<image.nj())
44  {
45  T2 v1 = image(i,j,plane);
46  double abs_diff = (v0<v1?(v1-v0):(v0-v1));
47  if (abs_diff < min_v) { min_v = abs_diff; }
48  }
49  }
50  return min_v;
51 }
52 
53 //: Computes shuffle distance between image1 and image2
54 // For each pixel in image1 it finds the pixel in image2 with
55 // the closest value in an offset area defined by the element.
56 // Returns mean over all pixels of this minimum value.
57 // Images must be of same size.
58 // If include_borders is false then only include pixels
59 // for which the structuring element is entirely within the image.
60 // \relatesalso vil_image_view
61 // \relatesalso vil_structuring_element
62 template <class T1, class T2>
63 double vil_abs_shuffle_distance(const vil_image_view<T1>& image1,
64  const vil_image_view<T2>& image2,
65  const vil_structuring_element& element,
66  bool include_borders=true);
67 
68 #endif // vil_abs_shuffle_distance_h_
Structuring element for morphology represented as a list of non-zero pixels.
const std::vector< int > & p_j() const
j position of elements (i,j).
Structuring element for morphology represented as a list of non-zero pixels.
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
double vil_abs_shuffle_distance(T1 v0, const vil_image_view< T2 > &image, unsigned plane, const vil_structuring_element &element, int i0, int j0)
Return min difference of pixels under structuring element centred at (i0,j0).
unsigned ni() const
Width.
unsigned nj() const
Height.
A base class reference-counting view of some image data.
const std::vector< int > & p_i() const
i position of elements (i,j).