On 04/02/2011 21:30, Michael Repucci wrote:
> Dear vxl-users,
> I have 3 questions, which are somewhat of a follow-up to a previous
> thread I started
> I was temporarily occupied with other responsibilities, but have now
> returned to the problem I was having, and can't seem to find a
> solution. With Ian's help, I've made some progress. As mentioned in
> my last post, I have many types of (huge) images (e.g., 1x8, 1x16,
> 3x16, 4x16 not RGBA), so I start with an image resource:
> vil_image_resource_sptr pResource = vil_load_image_resource(name);
> Then, as Ian suggested, I use pResource->pixel_format() to determine
> what I will call my "native" view:
> vil_image_view<vxl_uint_16> nativeView = pResource->get_view(i,
> ni, j, nj);
> But now I need to know what the different planes are, so I can know
> which ones to use when I need to display the image or combine
> information across planes. But according to this post
> (http://sourceforge.net/mailarchive/message.php?msg_id=8353305), VXL
> can't tell me what each plane is. So my first question (1): in the
> three years since that post, is that still true? I know the
> information is in the image file header, so if VXL has a was a way to
> query that, I could use that. If so, please give an example. Thanks!
Which image format are you using?
I'm not aware of any consistent way of describing each channel under all
reasonable use-cases. eg, varying frequency response curves, or spatial
or time-derivative channels. This would make it difficult to put such a
thing in the image-resource properties API. However, if your particular
file format has a standard way of describing the channels then you could
expose that as a class-specific attribute on the particular file-format
for RGB images, irrespective of the underlying memory layout, all files
should be loaded as plane 0 - Red, plane 1 - Green, plane 2 - Blue.
> If not, then let's assume I can get that information from somewhere
> else. Question (2): how can I create a view from nativeView that
> looks at only the (e.g.) second plane. I tried using the
> vil_image_view constructor referred to in the above post:
> vil_image_view<vxl_byte> singlePlaneView(nativeView.memory_chunk(),
> nativeView.top_left_ptr(), nativeView.ni(), nativeView.nj(), 1,
> nativeView.istep(), nativeView.jstep(), 2*nativeView.planestep());
you want to move the top-left ptr to the start of the plane you are
interested in. So that should be
nativeView.ni(), nativeView.nj(), 1,
nativeView.istep(), nativeView.jstep(), nativeView.planestep());
(the last parameter is largely irrelevant for a single plane image.)
Or you could just use vil_plane()
> But singlePlaneView.top_left_ptr() doesn't seem to point to
> contiguous memory corresponding to just the second plane. So I must
> be doing something wrong.
If you original image is laid out RGBRGBRGB..., then your single-plane
view of the underlying data will not be contiguous.
> And question (3), if I'd like to reorder the representation in memory
> of (a possible subset of) the planes, say from BGRA to RGB, what do I
> have to do so that (e.g.) myRgbView.top_left_ptr() will point to
> contiguous memory? With this problem, I'm not even sure where to
> start, since I can't get a single plane, let alone combine them back
> together in arbitrary order.
Minor point: by calling it myRgbView you are implying that its is just a
view on the same underlying memory. you really want a brand new
// I assume here that, irrespective of the underlying memory,
// plane 0 is R, and plane 2 is B.
vil_image_view<vxl_byte> myRgbView(ni, nj, 3);
myRgbView.deep_copy(vil_planes(nativeView, 0, 1, 3));
> Examples would be especially appreciated, as I have a difficult time
> figuring out what to do from the VXL reference docs alone. Thank you
> very much for any help!
try the vxl book, or core\vil\examples\* for some more examples.