KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flow_integral_flow.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Jinyan Guan, Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id: flow_integral_flow.h 17393 2014-08-23 20:19:14Z predoehl $ */
20 
21 #ifndef KJB_FLOW_INTEGRAL_FLOW_H
22 #define KJB_FLOW_INTEGRAL_FLOW_H
23 
24 #include <m_cpp/m_matrix.h>
26 #include <vector>
27 #include <algorithm>
28 #include <utility>
29 #include <string>
30 
31 namespace kjb {
32 
39 {
40 public:
45  Integral_flow(const Matrix& flow, size_t subsample_rate = 1);
46 
50  Integral_flow(const std::string& fname);
51 
57  double flow_sum(double x, double y) const;
58 
62  double flow_sum(const Axis_aligned_rectangle_2d& box) const
63  {
64  double left = std::max(0.0, box.get_left());
65  double right = std::min(box.get_right(), img_width_ - 1.0);
66  //double bottom = std::max(0.0, box.get_top());
67  double bottom = std::min(box.get_top(), img_height_ - 1.0);
68  //double top = std::min(box.get_bottom(), (double)img_height_);
69  double top = std::max(0.0, box.get_bottom());
70 
71  /*if(left >= img_width_
72  || right < 0
73  || bottom >= img_height_
74  || top < 0)
75  {
76  return 0.0;
77  }
78  */
79  if(right < 0.0
80  || left >= img_width_
81  || bottom < 0.0
82  || top >= img_height_)
83  {
84  return 0.0;
85  }
86 
87  double fs = flow_sum(right, bottom) + flow_sum(left, top)
88  - flow_sum(left, bottom) - flow_sum(right, top);
89 
90  return fs;
91  }
92 
93  void write(const std::string& fname);
94 
95  size_t img_width() const { return img_width_; }
96  size_t img_height() const { return img_height_; }
97 
98 private:
103  double at(size_t row, size_t col) const
104  {
105  return image_[row*width_ + col];
106  }
107 
111  std::pair<size_t, size_t> ul_corner(double x, double y) const
112  {
113  return std::make_pair(x / ss_rate_, y / ss_rate_);
114  }
115 
116  size_t ss_rate_;
117  size_t img_width_;
118  size_t img_height_;
119  size_t width_;
120  size_t height_;
121  std::vector<float> image_;
122 };
123 
124 } //namespace kjb
125 
126 #endif /*KJB_FLOW_INTEGRAL_FLOW_H */
127 
size_t img_height() const
Definition: flow_integral_flow.h:96
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
Class that represents an axis-aligned 2D rectangle. It is defined in terms of its (2D) center...
Definition: gr_2D_bounding_box.h:51
void write(const std::string &fname)
Definition: flow_integral_flow.cpp:180
double flow_sum(double x, double y) const
Returns the (interpolated) value of the integral flow at (x, y); i.e., computes the sum of flow in th...
Definition: flow_integral_flow.cpp:129
double get_bottom() const
Definition: gr_2D_bounding_box.h:99
double get_right() const
Definition: gr_2D_bounding_box.h:98
x
Definition: APPgetLargeConnectedEdges.m:100
double flow_sum(const Axis_aligned_rectangle_2d &box) const
Returns the sum of flows inside the given box.
Definition: flow_integral_flow.h:62
Integral_flow(const Matrix &flow, size_t subsample_rate=1)
Construct an integral flow object from the given flow matrix and sub-sampling rate.
Definition: flow_integral_flow.cpp:39
double get_left() const
Definition: gr_2D_bounding_box.h:97
double get_top() const
Definition: gr_2D_bounding_box.h:100
Int_matrix::Value_type min(const Int_matrix &mat)
Return the minimum value in this matrix.
Definition: l_int_matrix.h:1385
Definition: flow_integral_flow.h:38
Class representing an axis-aligned, 2D rectangle.
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
size_t img_width() const
Definition: flow_integral_flow.h:95