9 # include <vcl_msvc_warnings.h> 25 std::vector<vil_image_resource_sptr> rescs = il.
resources();
26 if (rescs.size() < 2L)
29 pil->set_directory(directory);
42 const std::string& full_filename,
43 char const* file_format,
48 std::cout <<
"Copying base resource\n";
50 if (!brsc||brsc->size_block_i()%2!=0||brsc->size_block_i()%2!=0)
56 brsc->ni(), brsc->nj(),
64 for (
unsigned int j = 0; j<brsc->n_block_j(); ++j)
65 for (
unsigned int i = 0; i<brsc->n_block_i(); ++i)
70 if (!out_resc->put_block(i, j, *blk))
81 static std::string level_filename(std::string& directory, std::string& filename,
93 return directory + slash + filename +
"_" + cs.str();
102 unsigned int nlevels,
104 char const* level_file_format,
110 std::string d = directory;
111 std::string fn = filename;
112 std::string full_filename = level_filename(d,fn, 0.0f) +
'.'+ level_file_format;
116 if (!copy_base_resc(base_image, full_filename,
117 level_file_format, blk_base))
130 for (
unsigned int L = 1; L<nlevels; ++L)
132 std::cout <<
"Decimating Level " << L << std::endl;
133 full_filename = level_filename(d, fn,
float(L)) +
'.'+ level_file_format;
138 std::vector<vil_image_resource_sptr> rescs = il.
resources();
159 for (
const auto & image : images)
178 for (
unsigned int i = 0; i<
nlevels; ++i)
191 auto ni0 = static_cast<float>(
levels_[0]->image_->ni());
192 for (
unsigned int i = 1; i<
nlevels; ++i)
193 levels_[i]->scale_ = static_cast<float>(
levels_[i]->image_->ni())/ni0;
198 unsigned int ni = image->ni(),
nj = image->nj();
199 for (
unsigned int L = 0; L<this->
nlevels(); ++L)
233 auto base_ni = static_cast<float>(
levels_[0]->image_->ni());
234 return static_cast<float>(image->ni())/base_ni;
244 std::string copy_name =
"copyR";
245 std::string file = level_filename(
directory_,copy_name, level);
246 std::string ffmt =
"pgm";
247 if (image->file_format())
248 ffmt = image->file_format();
249 file = file +
'.'+ ffmt;
250 unsigned int sbi = 0, sbj = 0;
253 { sbi = bir->size_block_i(); sbj = bir->size_block_j(); }
257 #ifdef VIL_USE_FSTREAM64 258 vil_stream_fstream64* os =
new vil_stream_fstream64(file.c_str(),
"w");
259 #else //VIL_USE_FSTREAM64 261 #endif //VIL_USE_FSTREAM64 263 image->nplanes(), image->pixel_format(),
268 image->ni(), image->nj(),
270 image->pixel_format(),
287 float mind = 1.0e08f;
288 unsigned int lmin = 0;
289 for (
unsigned int i = 0; i<
nlevels; ++i)
291 float ds = std::fabs(std::log(
levels_[i]->scale_ / scale));
306 unsigned int j0,
unsigned int n_j,
307 unsigned int level)
const 311 std::cerr <<
"pyramid_image_list::get_copy_view(.) level = " 312 << level <<
" max level = " 317 float actual_scale = pl->
scale_;
319 float fi0 = actual_scale*i0, fni = actual_scale*n_i, fj0 = actual_scale*j0, fnj = actual_scale*n_j;
321 auto si0 = static_cast<unsigned int>(fi0);
322 auto sni = static_cast<unsigned int>(fni);
323 if (sni == 0) sni = 1;
324 auto sj0 = static_cast<unsigned int>(fj0);
325 auto snj = static_cast<unsigned int>(fnj);
326 if (snj == 0) snj = 1;
330 std::cerr <<
"pyramid_image_list::get_copy_view(.) level = " 331 << level <<
"(i0,j0):(" 332 << i0 <<
' ' << j0 <<
") (ni, nj):(" 333 << n_i <<
' ' << n_j <<
")\n" 334 <<
"Get copy view from level image failed\n";
343 unsigned int j0,
unsigned int n_j,
345 float& actual_scale)
const 354 actual_scale = pl->
scale_;
std::vector< vil_image_resource_sptr > resources()
finds all the image files in the directory, regardless of extension.
bool add_resource(vil_image_resource_sptr const &image)
Add an image resource directly to the pyramid without copying.
A templated smart pointer class.
static bool vil_is_directory(char const *)
utility functions.
vil_image_resource_sptr image_
the resource.
static vil_image_resource_sptr decimate(vil_image_resource_sptr const &resc, char const *filename, char const *format="tiff")
Utility for decimating a resource to create a new pyramid level.
vil_image_resource_sptr vil_new_image_resource(unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format format)
Make a new image of given format.
A vil_stream implementation using std::fstream.
float scale_
scale associated with level.
A cached and blocked representation of the image_resource.
pyramid_level * closest(const float scale) const
find the image resource with scale closest to specified scale.
vil_blocked_image_resource_sptr vil_new_blocked_image_resource(vil_stream *os, unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format format, unsigned size_block_i, unsigned size_block_j, char const *file_format)
Make a new blocked resource file.
unsigned int nj() const override
The number of pixels in each column.
unsigned int cur_level_
the current pyramid level for this resource.
read an image from a file
bool put_resource(vil_image_resource_sptr const &image) override
Copy an image resource to the pyramid.
bool is_same_size(vil_image_resource_sptr const &image)
input image is the same size as one already in the pyramid.
A vil_stream implementation using std::fstream.
vil_blocked_image_resource_sptr blocked_image_resource(const vil_image_resource_sptr &ir)
cast to blocked resource if possible.
A blocked image facade for any image resource.
Various image copying functions.
Abstract representation of an image source or image destination.
float find_next_level(vil_image_resource_sptr const &image)
find the nearest level to the image size.
void normalize_scales()
normalize the scale factors so that the base image scale = 1.0.
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
An image resource list reader. Finds all resources of a type in the given directory.
unsigned int nlevels() const override
number of levels in the pyramid.
~vil_pyramid_image_list() override
vil_image_resource_sptr vil_load_image_resource(char const *filename, bool verbose=true)
Load an image resource object from a file.
bool vil_copy_deep(const vil_image_resource_sptr &src, vil_image_resource_sptr &dest)
Copy src to dest.
unsigned int ni() const override
The number of pixels in each row.
T * ptr() const
These methods all return the raw/dumb pointer.
A pyramid image resource based on multiple file-based image resources.
std::vector< pyramid_level * > levels_