That's really helpful. Thank you Ian!

Is there an alternative way to convert a multi-plane image into RGB or grey, other than the vil_convert_to_n_planes? What I'm hoping for is something similar to vil_convert_rgb_to_grey, where I can pass in the weights. The reason is that I will be working with some 4x16 bit images, and simply dropping the 4th channel as vil_convert_to_n_planes does, isn't sufficient for my application. I'd be happy to do this "manually" by combining the planes, but it's unclear to me how I might do that. Would vil_math_add_image_fraction work if I passed it single-plane views?

BTW, in your example below, and in the documentation, the order of the arguments to vil_convert_to_n_planes is backwards, at least on the revision I'm working from (r30389).

:) Michael

On Wed, Dec 15, 2010 at 6:23 AM, Ian Scott <scottim@imorphics.com> wrote:
Michael,

You can ask a vil_image_resource for it's pixel_format and number of planes:

switch(pResource->pixel_format())
{
 case VIL_PIXEL_FORMAT_BYTE:
 {
   if (pResource->nplanes()==3)

   {
     vil_image_view<vil_rgb<vxl_byte> > iView =
       pResource->get_view(100,200,100,200);
     ...
   }
 }
 case ...
}

Alternatively you could use the vil_convert functions
http://public.kitware.com/vxl/doc/release/core/vil/html/vil__convert_8h.html
to coerce whatever type the image_resource is using to a desired format:


vil_image_view<vil_rgb<vxl_byte> > iView =
 vil_convert_to_component_order(
   vil_convert_to_n_planes(
     vil_convert_stretch_range(vxl_byte(),

       pResource->get_view(100,200,100,200)
       ),
     3)
   );

This functionality is mostly documented with respect to vil_load(filename), however, it works identically when used with im_resource_ptr->get_view();

Ian.



On 14/12/2010 20:15, Michael Repucci wrote:
Hi VXL users,

I'm new to VXL. I've got some very large images that I'm opening, not in
one go, but via a vxl_image_resource. But I'm having a problem when I
try to get a view on the resource. The problem is that I don't know
ahead of time what kind of image I might be opening. They can be of
various formats (e.g., TIFF, BMP, JPG, NTF), and various bit depths
(e.g., 1x8, 1x16, 3x8, 4x16). So, for example, if I just naively call:

vil_image_resource_sptr pResource =
vil_load_image_resource(nameAsConstChar);
vil_image_view<vil_rgb<vxl_byte>> iView =
pResource->get_view(100,200,100,200);

on an image with 1x16 bit depth, I get an exception on the second line
that says "Pixel formats incompatible". Is it possible to query the
image resource to get this information? I looked through the
documentation and couldn't find an example or a method on
vil_image_resource that would provide this information. Maybe I missed it.

Any help and/or pointers to documentation would be greatly appreciated.
Thanks in advance!

:) Michael