Simon Druin asked:
> Is it possible to get info about an image (size, number of planes,
> etc..) on disk without actually loading the whole image?
Amitha mistakenly answered :-)
> Not with vil. At least, not easily, and not in general.
Peter followed Amitha's lead :-)
> It's maybe a good idea to add this kind of functionality to the vil
> file_formats "interface", i.e., implement --for each file type-- a
> required method which returns ni, nj, nplanes by just looking at the
> file header.
Sorry about the delay in answering - not been at a computer for 3 days.
The vil API explicitly supports this "use case". See the code below for
NB There may be some image loaders that don't do this as efficiently as
you might hope, but instead load in the whole image during the call to
vil_load_image_resource(). But the general idea is to (and most of the
formats do) only read the header information at this stage. You need to
call data->get_view() to actually read the pixel values off disk.
This vil_image_resource stuff is the how the core image loading and
saving is done. Versions of vil load which load in the whole image at
one actually use this stuff to do all the work.
// \brief Example of creating, processing and using an image data object
// \author Ian Scott
//: Analyse an image file without reading the pixels.
int main(int argc, char** argv)
if (argc < 2)
vcl_cerr << "Specify an image filename\n";
vcl_cout<<"Load " << argv << " into an image data object\n";
// This is how we initialise an image resource object.
vil_image_resource_sptr data = vil_load_image_resource(argv);
vcl_cerr << "Couldn't load " << argv <<vcl_endl;
vcl_cout << "Loaded " << argv <<vcl_endl;
<<" size: " << data->ni() << 'x' << data->nj() << '\n'
<<" planes: " << data->nplanes() << '\n'
<<" pixel type: " << data->pixel_format() << vcl_endl;