Image* resize(T& image, const Dim& dim, int resize_quality) { typename T::data_type* data = new typename T::data_type (dim, image.origin()); ImageView<typename T::data_type>* view = new ImageView<typename T::data_type>(*data); /* Images with nrows or ncols == 1 cannot be scaled by VIGRA. This is a hack that just returns an image with the same color as the upper-left pixel */ if (image.nrows() <= 1 || image.ncols() <= 1 || view->nrows() <= 1 || view->ncols() <= 1) { std::fill(view->vec_begin(), view->vec_end(), image.get(Point(0, 0))); return view; } if (resize_quality == 0) { // for straight scaling, resampleImage must be used in VIGRA double xfactor = (double)view->ncols()/image.ncols(); double yfactor = (double)view->nrows()/image.nrows(); // this is implemented incorrectly in VIGRA: //resizeImageNoInterpolation(src_image_range(image), dest_image_range(*view)); // the following works however: // requires extension of VIGRA (see basicgeometry.hxx) // that are not yet merged into VIGRA 1.6.0 resampleImage(src_image_range(image), dest_image(*view), xfactor, yfactor); } else if (resize_quality == 1) { resizeImageLinearInterpolation(src_image_range(image), dest_image_range(*view)); } else { resizeImageSplineInterpolation(src_image_range(image), dest_image_range(*view)); } image_copy_attributes(image, *view); return view; }