Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "vimt_image_2d.h"
00007 #include <vgl/vgl_point_2d.h>
00008 #include <vgl/vgl_vector_2d.h>
00009
00010
00011
00012
00013 vcl_vector<unsigned> vimt_image_2d::image_size() const
00014 {
00015 vcl_vector<unsigned> d(2);
00016 d[0]=image_base().ni();
00017 d[1]=image_base().nj();
00018 return d;
00019 }
00020
00021
00022
00023 vcl_vector<double> vimt_image_2d::pixel_size() const
00024 {
00025 vcl_vector<double> d(2);
00026 vgl_vector_2d<double> v =world2im_.inverse().
00027 delta(vgl_point_2d<double>(0,0), vgl_vector_2d<double>(1.0,1.0));
00028
00029 d[0] = v.x();
00030 d[1] = v.y();
00031 return d;
00032 }
00033
00034
00035
00036 void vimt_image_2d::world_bounds(vcl_vector<double>& b_lo,
00037 vcl_vector<double>& b_hi) const
00038 {
00039 b_lo.resize(2); b_hi.resize(2);
00040 vgl_point_2d<double> p = world2im_.inverse()(0,0);
00041 b_lo[0]=p.x(); b_hi[0]=p.x();
00042 b_lo[1]=p.y(); b_hi[1]=p.y();
00043
00044
00045 for (int i=0;i<2;++i)
00046 for (int j=0;j<2;++j)
00047 {
00048 p = world2im_.inverse()(i*(image_base().ni()-1),j*(image_base().nj()-1));
00049 if (p.x()<b_lo[0]) b_lo[0]=p.x();
00050 else if (p.x()>b_hi[0]) b_hi[0]=p.x();
00051 if (p.y()<b_lo[1]) b_lo[1]=p.y();
00052 else if (p.y()>b_hi[1]) b_hi[1]=p.y();
00053 }
00054 }
00055
00056
00057
00058
00059
00060 vgl_box_2d<double> world_bounding_box(const vimt_image_2d& img)
00061 {
00062 vcl_vector<double> b_lo(2,0.0);
00063 vcl_vector<double> b_hi(2,0.0);
00064 img.world_bounds(b_lo,b_hi);
00065 return vgl_box_2d<double>(b_lo[0],b_hi[0],b_lo[1],b_hi[1]);
00066 }
00067
00068
00069 void vimt_centre_image_at_origin(vimt_image_2d& image)
00070 {
00071 vgl_box_2d<double> bbox = world_bounding_box(image);
00072 vgl_point_2d<double> c = bbox.centroid();
00073 vimt_transform_2d& w2i = image.world2im();
00074 w2i.set_origin(w2i(c));
00075 }
00076
00077
00078
00079 vgl_vector_2d<double> vimt_pixel_size_from_transform(const vimt_image_2d& image)
00080 {
00081 const vimt_transform_2d& i2w = image.world2im().inverse();
00082 vgl_point_2d<double> p(0,0);
00083 vgl_vector_2d<double> i(1,0);
00084 vgl_vector_2d<double> j(0,1);
00085 double dx = i2w.delta(p, i).length();
00086 double dy = i2w.delta(p, j).length();
00087 return vgl_vector_2d<double>(dx, dy);
00088 }