17 #include "SimpleOpt.h"
21 #include <vnl/vnl_matrix.h>
22 #include <vnl/algo/vnl_matrix_inverse.h>
27 {
OPT_H, _T(
"-H"), SO_REQ_SEP },
28 {
OPT_BOX, _T(
"-xm"), SO_REQ_SEP },
29 {
OPT_BOX, _T(
"-xM"), SO_REQ_SEP },
30 {
OPT_BOX, _T(
"-ym"), SO_REQ_SEP },
31 {
OPT_BOX, _T(
"-yM"), SO_REQ_SEP },
48 vnl_matrix<double>
H_;
56 Hinv_ = vnl_matrix_inverse<double>(H).as_matrix();
69 vnl_vector<double> po(3);
73 vnl_vector<double> pn =
H_*po;
81 vnl_vector<double> pn(3);
85 vnl_vector<double> po =
Hinv_*pn;
88 if (xo<(
double)
box_in_[0])
return false;
89 if (xo>(
double)
box_in_[1])
return false;
90 if (yo<(
double)
box_in_[2])
return false;
91 if (yo>(
double)
box_in_[3])
return false;
97 #include "h_remap.help"
101 int main(
int argc,
char ** argv)
103 vnl_matrix<double> H(3,3);
104 vnl_matrix<double> Hinv(3,3);
105 bool given_h =
false;
106 bool get_box_out =
false;
108 int val_code = 1000000;
113 if (args.LastError() == SO_SUCCESS)
119 else if (args.OptionId() ==
OPT_H)
121 std::ifstream
in(args.OptionArg());
124 std::cerr <<
"Cannot open file" << std::endl;
131 std::cerr <<
"Matrix H should be 3x3" << std::endl;
134 for (
int i=0;i<3;i++)
136 for (
int j=0;j<3;j++)
145 else if (args.OptionId() ==
OPT_BOX)
147 std::ostringstream o;
148 o << args.OptionArg();
149 std::istringstream
in(o.str().c_str());
152 if (args.OptionText() == std::string(
"-xm"))
154 else if (args.OptionText() == std::string(
"-xM"))
156 else if (args.OptionText() == std::string(
"-ym"))
158 else if (args.OptionText() == std::string(
"-yM"))
164 std::cerr <<
"Invalid argument: " << args.OptionText() << std::endl;
165 return error(args.LastError());
172 if (args.FileCount() != 1)
return error(-4);
176 if (args.FileCount() != 2)
return error(-4);
178 if (!given_h)
return error(-5);
181 remap.
read(args.File(0));
182 if (
xm != val_code) remap.
xm(
xm);
183 if (
xM != val_code) remap.
xM(
xM);
184 if (
ym != val_code) remap.
ym(
ym);
185 if (
yM != val_code) remap.
yM(
yM);
192 remap.
write(args.File(1));
vnl_matrix< double > Hinv_
a_h_remap(const vnl_matrix< double > &H)
bool old_coordinates(double xn, double yn, double &xo, double &yo)
gives the pixel coordinates in the input image in function of the pixel coordinates in the output ima...
void new_coordinates(double xo, double yo, double &xn, double &yn)
gives the pixel coordinates in the output image in function of the pixel coordinates in the input ima...
a unit to deform an image. The transformation function needs to be defined in a children class.
void yM(const int val)
impose the size of the output bounding box
void xm(const int val)
impose the size of the output bounding box
void write(const std::string &name)
write the processed image to a file
void deform()
deform the image
void xM(const int val)
impose the size of the output bounding box
virtual void read(const std::string &name)
read the image to be processed
virtual void box_out()
compute the bounding box of the new image
void ym(const int val)
impose the size of the output bounding box
double v(const uint32_t step, const uint32_t n)
CSimpleOpt::SOption g_rgOptions[]
int main(int argc, char **argv)