From: Ian S. <ian...@st...> - 2006-12-11 11:59:47
|
Andrea Carbone wrote: > Hello, > > got a couple of basic questions. > > Plaform WinXP, VC8, last vxl CVS > > I am quite new to vxl and want to submit a couple of questions: > > column major: > > I am writing some routine for matlab. > Matlab represents images (and matrices as well) as fortran. > That is column major. > >>From a matlab runtime I can gather the raw address of an image and > process it in C++. > > This is the code: > > //the raw pointer to the data > vxl_byte* input_image_ptr = > static_cast<vxl_byte*>(mxGetData(MX_INPUT_IMAGE)); > > // n is number of columns > size_t n = mxGetN(MX_INPUT_IMAGE); > // m is number of rows > size_t m = mxGetM(MX_INPUT_IMAGE); > > I am quite puzzled abouot the vil_image_view ctor. > As far as I know, It should be possible to construct vil_image_view > directly from the column_major representation, by specifying custom > istep and jstep. > But I had success only by defining the vil_inage in this way: > > // > vil_image_view<vxl_byte> base_image_view(input_image_ptr > ,m,n //dimensions > ,1,1 > ,1 > ,m*n); > > Of course, in this way I get a transposed version of the input image, > because of the m and n flipped sizes. > Obviously if I pass a pre-transposed version of the image, when I save > the image (the vil_image_view) I get the exact copy of the orignal. > > Initially I wrote: > //This should be the logical ctor AFAIK > vil_image_view<vxl_byte> base_image_view(input_image_ptr > ,n,m //n cols, m rows > ,m,1 //istep, jstep > ,1 //depth > ,m*n);//num of pixels > > But when saving I got a runtime error. > I am missing something.... I don't know about you, but this email is missing 1. A complete description of the runtime error 2. Your code that generates and saves the image. At a guess, however, you have got the constructor wrong. The documentation says vil_image_view< T >::vil_image_view ( const T * top_left, unsigned ni, unsigned nj, unsigned nplanes, vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step, vcl_ptrdiff_t plane_step ) So I'd try vil_image_view<vxl_byte> base_image_view(input_image_ptr ,n,m //n cols, m rows ,1 //depth ,m,1 //istep, jstep ,m*n);//plane step If you still have problems, please resubmit your problem with a complete description. > > Second. > I try to build a gaussian pyramidal representation of the original > image. Using the mul/vimt library. > > I cannot succeed to see an output because I am not able to extract the > individual levels. > > This is the code: > > // > printf("vil_convert_cast\n"); > vimt_image_2d_of<float> base_image_f; > vil_convert_cast(base_image_view, base_image_f.image() ); > > // > printf("Vimt Pyramid\n"); > vimt_image_pyramid image_pyr; > vimt_gaussian_pyramid_builder_2d<float> builder; > // > builder.build(image_pyr, base_image_f); > > This instructions fails to compile: > > builder.build(image_pyr, base_image_f); > vimt_image_2d_of<float> level2; > level2 = image_pyr(2) ; > >> 1>..\alcor2\matlab\mex_pyr_builder.cpp(88) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'vimt_image' (or there is no acceptable conversion) >> 1> C:\Programmi\vxl\include\vxl\contrib\mul\vimt/vimt_image_2d_of.h(103): could be 'vimt_image_2d_of<T> &vimt_image_2d_of<T>::operator =(const vimt_image_2d_of<T> &)' >> 1> with >> 1> [ >> 1> T=float >> 1> ] >> 1> while trying to match the argument list '(vimt_image_2d_of<T>, vimt_image)' >> 1> with >> 1> [ >> 1> T=float >> 1> ] > > How can I access the levels? > You almost have it right. vimt and vil have slightly different abstraction levels, mainly for historical and evolutionary reasons. In particular vimt is designed for moving around registered images where you don't know the pixel type (or even the dimensionality) of your image. So images can be represented as a reference to an abstract base class vimt_image. This allows us to use the strategy pattern (See Gamma et al.) and pass around images through code that works equally well on an abstract 2D or 3D image, before ending up in the concrete strategy objecy that already knows that it is supposed to sample a 3D float image for example. The image pyramid doesn't know anything about the images is contains. All it knows is that it has a stack of vimt_image objects. You, as the client of the pyramid who wants a concrete image, know that you have a vimt_image_2d_of<float>, so use a static_cast (or dynamic_cast if you want to be cautious) I think that the following should work, but I haven't checked the const correctness. vimt_image_2d_of<float> level2; level2 = static_cast<vimt_image_2d_of<float>&> (image_pyr(2)) ; Ian. |