Go to the documentation of this file.00001
00002 #include "gevd_region_proc.h"
00003
00004
00005
00006 #include <gevd/gevd_float_operators.h>
00007 #include <gevd/gevd_detector.h>
00008 #include <gevd/gevd_clean_edgels.h>
00009 #include <gevd/gevd_edgel_regions.h>
00010 #include <vtol/vtol_intensity_face.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019 gevd_region_proc::gevd_region_proc()
00020 {
00021 debug_=false;
00022
00023
00024 buf_ = 0;
00025 }
00026
00027
00028 gevd_region_proc::~gevd_region_proc()
00029 {
00030 delete buf_;
00031 }
00032
00033
00034
00035
00036 gevd_bufferxy* gevd_region_proc::get_image_buffer(vil1_image& image)
00037 {
00038 if (!image)
00039 return NULL;
00040 if (image.planes() != 1)
00041 return NULL;
00042
00043 int wd = image.width();
00044 int ht = image.height();
00045 int sz = image.components() * image.bits_per_component();
00046 gevd_bufferxy* buf = new gevd_bufferxy(wd, ht, sz);
00047 image.get_section(buf->GetBuffer(), 0, 0, wd, ht);
00048 return buf;
00049 }
00050
00051
00052
00053
00054 gevd_bufferxy* gevd_region_proc::get_float_buffer(gevd_bufferxy* buf)
00055 {
00056 if (!buf)
00057 return NULL;
00058 gevd_bufferxy* fbuf = new gevd_bufferxy(buf->GetSizeX(),
00059 buf->GetSizeY(),
00060 8*sizeof(float));
00061 gevd_float_operators::BufferToFloat(*buf, *fbuf);
00062 return fbuf;
00063 }
00064
00065
00066
00067
00068
00069 gevd_bufferxy* gevd_region_proc::put_float_buffer(gevd_bufferxy* fbuf)
00070 {
00071 if (!fbuf)
00072 return NULL;
00073
00074 gevd_bufferxy* pbuf = new gevd_bufferxy(fbuf->GetSizeX(), fbuf->GetSizeY(), 16);
00075 gevd_float_operators::FloatToBuffer(*fbuf, *pbuf);
00076 return pbuf;
00077 }
00078
00079
00080
00081 void gevd_region_proc::set_image(vil1_image& image)
00082 {
00083 if (!image)
00084 {
00085 vcl_cout <<"In gevd_region_proc::set_image(.) - null input\n";
00086 return;
00087 }
00088 regions_valid_ = false;
00089 image_ = image;
00090 if (buf_)
00091 {
00092 delete buf_;
00093 buf_ = NULL;
00094 }
00095
00096 if (expand_scale_==1.0f)
00097 {
00098 buf_ = this->get_image_buffer(image_);
00099 return;
00100 }
00101 else if (expand_scale_==2.0f)
00102 {
00103 gevd_bufferxy* temp = this->get_image_buffer(image_);
00104 if (!temp)
00105 {
00106 vcl_cout <<"In gevd_region_proc::set_image(.) "
00107 <<"- couldn't get gevd_bufferxy from the image\n";
00108 return;
00109 }
00110 gevd_bufferxy* fbuf = this->get_float_buffer(temp);
00111 gevd_bufferxy* expand = NULL;
00112 gevd_float_operators::ExpandBy2(*fbuf, expand, burt_adelson_factor_);
00113 gevd_float_operators::TruncateToPositive(*expand);
00114 buf_ = this->put_float_buffer(expand);
00115 delete temp;
00116 delete fbuf;
00117 delete expand;
00118 return;
00119 }
00120 else if (expand_scale_==0.5f)
00121 {
00122 gevd_bufferxy* temp = this->get_image_buffer(image_);
00123 if (!temp)
00124 {
00125 vcl_cout <<"In gevd_region_proc::set_image(.) "
00126 <<"- couldn't get gevd_bufferxy from the image\n";
00127 return;
00128 }
00129 gevd_bufferxy* fbuf = this->get_float_buffer(temp);
00130 gevd_bufferxy* shrink = NULL;
00131 gevd_float_operators::ShrinkBy2(*fbuf, shrink, burt_adelson_factor_);
00132 gevd_float_operators::TruncateToPositive(*shrink);
00133 buf_ = this->put_float_buffer(shrink);
00134 delete temp;
00135 delete fbuf;
00136 delete shrink;
00137 return;
00138 }
00139 vcl_cout <<"In gevd_region_proc::set_image(.) - invalid expand scale factor\n";
00140 }
00141
00142
00143
00144 void gevd_region_proc::extract_regions()
00145 {
00146 if (regions_valid_)
00147 return;
00148
00149
00150 if (!buf_)
00151 {
00152 vcl_cout << "In gevd_region_proc::extract_regions() - no image\n";
00153 return;
00154 }
00155
00156 vcl_cout << "gevd_region_proc::extract_regions(): sizeX = "
00157 << buf_->GetSizeX() << " sizeY = " << buf_->GetSizeY() << vcl_endl;
00158
00159
00160 regions_.clear();
00161
00162
00163 gevd_detector detector ( image_);
00164
00165
00166 detector.junctionFactor = 1.0;
00167 detector.contourFactor = 2.0;
00168 detector.minLength = 4;
00169 detector.junctionp = 1;
00170 detector.smooth = 2.0;
00171 detector.borderp = 1;
00172
00173 detector.DoContour();
00174
00175 vcl_vector<vtol_edge_2d_sptr> * edgels = detector.GetEdges();
00176
00177 if (!edgels->size())
00178 {
00179 vcl_cout << "In gevd_region_proc::extract_regions()- No Edgels were computed\n";
00180 return;
00181 }
00182 #if 0 // commented out
00183 vcl_vector<vtol_edge_2d_sptr>::iterator eit; = edgels.begin();
00184 for (eit = edgels->begin(); eit != edgels->end(); eit++)
00185 {
00186 vcl_cout << "Edgel output from DoContour:";
00187 (*eit)->describe(vcl_cout,2);
00188 }
00189
00190 gevd_detector det(dp_);
00191 vcl_vector<vtol_edge_2d_sptr> broken_edgels;
00192 det.DoBreakCorners(edgels, broken_edgels);
00193 #endif
00194
00195 gevd_clean_edgels cl;
00196 vcl_vector<vtol_edge_2d_sptr> clean_edgels;
00197 cl.DoCleanEdgelChains(*edgels, clean_edgels);
00198 if (!clean_edgels.size())
00199 {
00200 vcl_cout << "In gevd_region_proc::extract_regions()- All edges removed by clean\n";
00201 return;
00202 }
00203 gevd_edgel_regions er(debug_);
00204 er.set_magnification(expand_scale_);
00205
00206
00207
00208 vcl_vector<vtol_intensity_face_sptr> faces;
00209
00210 er.compute_edgel_regions(buf_, clean_edgels, faces);
00211 #if 0 // commented out
00212
00213 if (expand_scale_!=0.0f)
00214 {
00215 float si = 1.0f/expand_scale_;
00216
00217
00218
00219 TwoChain_ref tc = new TwoChain(faces.length());
00220 for (vcl_vector<IntensityFace*>::iterator fit = faces.begin();
00221 fit != faces.end(); fit++)
00222 tc->add_face((Face*)(*fit), '1');
00223
00224 CoolTransform minus=CoolTransform::translation(-0.5, -0.5, 0.0);
00225 CoolTransform plus=CoolTransform::translation(0.5+xo, 0.5+yo, 0.0);
00226 CoolTransform scale = CoolTransform::stretching(si, si, 1.0);
00227 CoolTransform t = CoolTransform::identity();
00228
00229 t *= minus;
00230 t *= scale;
00231 t *= plus;
00232 tc->TaggedTransform(t);
00233 }
00234 #endif
00235
00236 vcl_vector<vtol_intensity_face_sptr>::iterator fit;
00237 for ( fit = faces.begin(); fit != faces.end(); fit++)
00238 {
00239
00240
00241
00242
00243 continue;
00244
00245
00246
00247
00248
00249
00250
00251 }
00252 regions_valid_ = true;
00253 }
00254
00255
00256
00257 void gevd_region_proc::clear()
00258 {
00259 regions_.clear();
00260 }