KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hog.h
Go to the documentation of this file.
1 /* $Id: hog.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Luca del Pero
18  * =========================================================================== */
19 
20 #ifndef KJB_CPP_EDGE_HOG_H
21 #define KJB_CPP_EDGE_HOG_H
22 
23 #include <l/l_incl.h>
24 #include <i_cpp/i_image.h>
25 #include <l_cpp/l_readable.h>
26 #include <l_cpp/l_writeable.h>
27 #include <cmath>
28 
29 #include <string>
30 
31 // small value, used to avoid division by zero
32 #define eps 0.0001
33 
34 namespace kjb
35 {
36 
37 static inline float hog_min(float x, float y) { return (x <= y ? x : y); }
38 static inline float hog_max(float x, float y) { return (x <= y ? y : x); }
39 
40 static inline int hog_min(int x, int y) { return (x <= y ? x : y); }
41 static inline int hog_max(int x, int y) { return (x <= y ? y : x); }
42 
43 void compute_HOG_features(const Image & img, int bin_size);
44 
45 class Hog_responses: public Readable, public Writeable
46 {
47 public:
48  Hog_responses(const Image & img, int ibin_size);
49 
50  Hog_responses(const std::string & file_name)
51  {
52  hog_responses = NULL;
53  Readable::read(file_name.c_str());
54  }
55 
56  Hog_responses(const Hog_responses & src) : Readable(src), Writeable(src), bin_size(src.bin_size),
57  num_rows(src.num_rows), num_cols(src.num_cols), hog_num_rows(src.hog_num_rows),
58  hog_num_cols(src.hog_num_cols), hog_size(src.hog_size)
59  {
60  hog_responses = new float[hog_size];
61  memcpy(hog_responses, src.hog_responses, hog_size*sizeof(float));
62  }
63 
65  {
66  delete[] hog_responses;
67  }
68 
70  {
71  bin_size = src.bin_size;
72  num_rows = src.num_rows;
73  num_cols = src.num_cols;
74  hog_num_rows = src.hog_num_rows;
75  hog_num_cols = src.hog_num_cols;
76  hog_size = src.hog_size;
77  delete[] hog_responses;
78  hog_responses = NULL;
79  hog_responses = new float[hog_size];
80  memcpy(hog_responses, src.hog_responses, hog_size*sizeof(float));
81  return (*this);
82  }
83 
84  inline int get_hog_num_rows() const
85  {
86  return ((int)round((double)num_rows/(double)bin_size)) -2;
87  }
88 
89  inline int get_hog_num_cols() const
90  {
91  return ((int)round((double)num_cols/(double)bin_size)) -2;
92  }
93 
94  int get_num_rows() const
95  {
96  return num_rows;
97  }
98 
99  inline int get_num_cols() const
100  {
101  return num_cols;
102  }
103 
104  inline int get_hog_pix_row(int img_pix_row) const
105  {
106  return (int)std::floor(((double)img_pix_row + 0.5)/(double)bin_size - 0.5);
107  }
108 
109  inline int get_hog_pix_col(int img_pix_col) const
110  {
111  return (int)std::floor(((double)img_pix_col + 0.5)/(double)bin_size - 0.5);
112  }
113 
114  inline int get_hog_cell_x_center(int hog_x_index) const
115  {
116  return 1.5 + bin_size + (bin_size*hog_x_index);
117  }
118 
119  inline int get_hog_cell_y_center(int hog_y_index) const
120  {
121  return 1.5 + bin_size + (bin_size*hog_y_index);
122  }
123 
124  void get_HOG_picture(Image & positive_image, Image & negative_image, bool & negative_weights);
125 
126  void get_bims(std::vector<Matrix> & bim);
127 
129  void read(std::istream& in);
130 
132  void write(std::ostream& out) const;
133 
134  inline int get_hog_size() const
135  {
136  return hog_size;
137  }
138 
139  inline const float * get_hog_responses() const
140  {
141  return hog_responses;
142  }
143 
144  inline int get_bin_size() const
145  {
146  return bin_size;
147  }
148 
149 private:
150  int bin_size;
151  int num_rows;
152  int num_cols;
153  int hog_num_rows;
154  int hog_num_cols;
155  int hog_size;
156  float * hog_responses;
157 };
158 
159 void rotate_matrix_90_degrees(Matrix & m, int number_of_times);
160 
162 void rotateMatrix(Matrix & m, double angle);
163 
164 } // namespace kjb
165 #endif
int get_num_rows() const
Definition: hog.h:94
void get_HOG_picture(Image &positive_image, Image &negative_image, bool &negative_weights)
Definition: hog.cpp:322
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
~Hog_responses()
Definition: hog.h:64
void read(std::istream &in)
Reads this Line segment from an input stream.
Definition: hog.cpp:249
int get_hog_cell_x_center(int hog_x_index) const
Definition: hog.h:114
Hog_responses(const Image &img, int ibin_size)
Definition: hog.cpp:23
void compute_HOG_features(const Image &img, int bin_size)
int get_hog_num_rows() const
Definition: hog.h:84
int get_num_cols() const
Definition: hog.h:99
Hog_responses(const Hog_responses &src)
Definition: hog.h:56
void get_bims(std::vector< Matrix > &bim)
Definition: hog.cpp:398
int get_hog_cell_y_center(int hog_y_index) const
Definition: hog.h:119
void rotateMatrix(Matrix &m, double angle)
int get_hog_pix_row(int img_pix_row) const
Definition: hog.h:104
Int_matrix floor(const Matrix &m)
Definition: m_matrix.cpp:2026
x
Definition: APPgetLargeConnectedEdges.m:100
Hog_responses(const std::string &file_name)
Definition: hog.h:50
int get_hog_pix_col(int img_pix_col) const
Definition: hog.h:109
Hog_responses & operator=(const Hog_responses &src)
Definition: hog.h:69
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
void write(std::ostream &out) const
Writes this Line segment to an output stream.
Definition: hog.cpp:313
Definition: hog.h:45
Code for a wrapper class around the C struct KJB_Image.
const float * get_hog_responses() const
Definition: hog.h:139
for m
Definition: APPgetLargeConnectedEdges.m:64
int get_hog_num_cols() const
Definition: hog.h:89
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
int get_bin_size() const
Definition: hog.h:144
int get_hog_size() const
Definition: hog.h:134
void rotate_matrix_90_degrees(Matrix &m, int number_of_times)
Definition: hog.cpp:504