20 #include "vigra/stdimage.hxx"
21 #include "vigra/resizeimage.hxx"
22 #include "vigra/impex.hxx"
23 #include "vigra/colorconversions.hxx"
24 #include <sys/types.h>
31 using namespace vigra;
36 cout <<
"Usage: " << filename <<
" <image file> <mask file>" << endl;
37 cout <<
"or for a positive example: " << filename <<
" -p <image file>" << endl;
38 cout <<
"or for a negative example: " << filename <<
" -n <image file>" << endl;
39 cout <<
"(supported formats: " << vigra::impexListFormats() <<
")" << endl;
42 int main(
int argc,
char ** argv){
47 string image_file,mask_file;
48 vigra::FRGBImage mask_in;
49 vigra::FRGBImage::iterator mask_iter;
52 if(argc < 3 || argc >= 4){
54 usage(argv[0]); exit(1);
59 if( argv[a][0] ==
'-'){
65 case 'h' : {
usage(argv[0]); exit(1);}
67 cerr <<
"Ignoring mask. Image is a positive example." << endl;
68 image_file = argv[argc-1];
72 cerr <<
"Ignoring mask. Image is a negative example." << endl;
73 image_file = argv[argc-1];
76 default : {
usage(argv[0]); exit(1);}
84 if (pos == 0 && neg == 0){
86 image_file = argv[argc-2];
87 mask_file = argv[argc-1];
96 cerr <<
"Opening image file: " << image_file << endl;
100 vigra::ImageImportInfo
info(image_file.c_str());
103 vigra::FRGBImage in(
info.width(),
info.height());
109 if (pos == 0 && neg == 0){
111 cerr <<
"Opening mask file: " << mask_file << endl;
114 vigra::ImageImportInfo mask_info(mask_file.c_str());
117 if (
info.width() != mask_info.width() ||
info.height() != mask_info.height()){
119 cerr <<
"Error - image and mask files are different dimension:" << endl;
120 cerr <<
"Image:\t" <<
info.width() <<
" x " <<
info.height() << endl;
121 cerr <<
"Mask:\t" << mask_info.width() <<
" x " << mask_info.height() << endl << endl;
127 vigra::FRGBImage tmp_mask_in(
info.width(),
info.height());
129 importImage(mask_info,
destImage(tmp_mask_in));
130 mask_in = tmp_mask_in;
136 const int resize_dimension = 800;
139 if (
info.width() >= resize_dimension ||
info.height() >= resize_dimension){
147 sizefactor = (double)resize_dimension/
info.width();
149 sizefactor = (double)resize_dimension/
info.height();
153 int nw = (int)(sizefactor*
info.width());
154 int nh = (int)(sizefactor*
info.height());
156 cerr <<
"Image dimensions:\t" <<
info.width() <<
" x " <<
info.height() << endl;
157 cerr <<
"Scaling by:\t\t" << sizefactor << endl;
158 cerr <<
"New dimensions:\t\t" << nw <<
" x " << nh << endl;
161 vigra::FRGBImage out(nw, nh);
183 if (pos == 0 && neg == 0){
185 vigra::FRGBImage mask_out(nw, nh);
209 cerr <<
"Image dimensions:\t" <<
info.width() <<
" x " <<
info.height() << endl;
212 cerr <<
"Total pixels:\t\t" << in.width()*in.height() << endl;
215 cerr <<
"Converting to LUV colourspace..." << endl;
217 FRGBImage luv(in.width(),in.height());
221 cerr <<
"Generating fiducial points..." << endl;
223 for (
int i = gRadius; i < in.height() - gRadius; i += spacing ){
224 for (
int j = gRadius; j < in.width() - gRadius; j += spacing ){
232 for (
int i = gRadius; i < in.height() - gRadius; i += spacing ){
233 for (
int j = gRadius; j < in.width() - gRadius; j += spacing ){
235 gLocations[gNumLocs][0] = j;
236 gLocations[gNumLocs][1] = i;
243 cerr <<
"Total fiducial points: " << gNumLocs << endl;
246 float *frameBuf =
new float[in.width()*in.height()];
247 float *u_values =
new float[in.width()*in.height()];
248 float *v_values =
new float[in.width()*in.height()];
251 float** pixels =
CreateMatrix( (
float)0, in.height(), in.width() );
255 vigra::FRGBImage::iterator img_iter(luv.begin()),end(luv.end());
256 for(; img_iter != end; ++img_iter) {
260 frameBuf[counter] = (*img_iter)[0];
262 u_values[counter] = (*img_iter)[1];
263 v_values[counter] = (*img_iter)[2];
273 for (
int i = 0; i < in.height(); i++ ){
274 for (
int j = 0; j < in.width(); j++ ){
275 pixels[i][j] = frameBuf[k];
281 char basename[] =
"gabor_filters/celeste";
289 if (pos == 0 && neg == 0){
292 vigra::FRGBImage::iterator tmp_mask_iter(mask_in.begin()),mask_end(mask_in.end());
293 mask_iter = tmp_mask_iter;
297 cerr <<
"Generating feature vector by Gabor filtering..." << endl;
300 int vector_length = (int)len/gNumLocs;
301 for (
int j = 0; j < gNumLocs; j++ ){
305 int pixel_number = gLocations[j][0] + (in.width() * (gLocations[j][1] - 1)) - 1;
314 if (mask_iter[pixel_number][0] != 0 || mask_iter[pixel_number][1] != 0 || mask_iter[pixel_number][2] != 0){
324 for (
int v = (j * vector_length); v < ((j + 1) * vector_length); v++){
325 cout << feature <<
":" << response[v] <<
" ";
331 float u_sum = 0, v_sum = 0;
332 int pixels_in_region = (gRadius * 2)*(gRadius * 2);
338 for (
int t = 1 - gRadius; t <= gRadius; t++){
340 int this_y_pixel = pixel_number + (t * in.width());
343 for (
int r = 1 - gRadius; r <= gRadius; r++){
345 int this_x_pixel = this_y_pixel + r;
353 u_sum += u_values[this_x_pixel];
354 v_sum += v_values[this_x_pixel];
364 float u_ave = (float)u_sum/pixels_in_region;
365 float v_ave = (float)v_sum/pixels_in_region;
368 u_sum = 0, v_sum = 0;
370 for (
int t = 1 - gRadius; t <= gRadius; t++){
371 int this_y_pixel = pixel_number + (t * in.width());
373 for (
int r = 1 - gRadius; r <= gRadius; r++){
375 int this_x_pixel = this_y_pixel + r;
377 u_sum +=
pow(u_values[this_x_pixel]-u_ave,2);
378 v_sum +=
pow(v_values[this_x_pixel]-v_ave,2);
384 float std_u = sqrt(u_sum/(pixels_in_region-1));
385 float std_v = sqrt(v_sum/(pixels_in_region-1));
390 cout << feature <<
":" << u_ave <<
" ";
392 cout << feature <<
":" << std_u <<
" ";
394 cout << feature <<
":" << v_ave <<
" ";
396 cout << feature <<
":" << std_v <<
" ";
401 cout << feature <<
":" << u_values[pixel_number] <<
" ";
403 cout << feature <<
":" << v_values[pixel_number] <<
" ";
428 }
catch (vigra::StdException & e){
431 std::cout << e.what() << std::endl;
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
float * ProcessChannel(float **image, int w, int h, int gNumLocs, int **&gLocations, int gRadius, float *response, int *len)
float pow(float a, double b)
static deghosting::EMoR response(0.0f)
int ** CreateMatrix(int val, int row, int col)
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
vigra::triple< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImageRange(ROIImage< Image, Alpha > &img)
static void info(const char *fmt,...)
int main(int argc, char *argv[])