This file contains a large number of image to image conversion functions. They are in two basic function types (plus a few helper functions.) Some involve only explicit types and convert a vil3d_image_view<T> to a vil3d_image_view<T>, the others take an inknown pixel type, using a vil3d_image_view_base_sptr. The basic conversion operations (e.g. casting, rounding) are available in both types. All of the conversions attempt to find shortcuts, so the output may be a reconfigured, or shallow copy of the input.
It may be a good idea to provide vil3d_image_resource_sptr based vil3d_converts as well.
Definition in file vil3d_convert.h.
#include <vcl_cassert.h>
#include <vcl_limits.h>
#include <vil/vil_convert.h>
#include <vil3d/vil3d_transform.h>
#include <vil3d/vil3d_math.h>
#include <vil3d/vil3d_plane.h>
#include <vil3d/vil3d_copy.h>
Go to the source code of this file.
Defines | |
| #define | macro(F, T) |
| #define | macro(F, T) |
| #define | macro(F, T) |
| #define | macro(F, T) |
| #define | macro(F, T) |
Functions | |
| template<class inP> | |
| void | vil3d_convert_stretch_range (const vil3d_image_view< inP > &src, vil3d_image_view< double > &dest, double lo, double hi) |
| Convert src to double image dest by stretching to range [lo,hi]. | |
| template<class inP> | |
| void | vil3d_convert_stretch_range_limited (const vil3d_image_view< inP > &src, vil3d_image_view< double > &dest, const inP src_lo, const inP src_hi, const double dest_lo, const double dest_hi) |
| Convert src image<inP> to dest image<double> by stretching input range [src_lo, src_hi] to output range [dest_lo, dest_hi]. | |
| template<class outP> | |
| vil3d_image_view_base_sptr | vil3d_convert_cast (outP, const vil3d_image_view_base_sptr &src) |
| Cast the unknown pixel type to the known one. | |
| template<class outP> | |
| vil3d_image_view_base_sptr | vil3d_convert_round (outP, const vil3d_image_view_base_sptr &src) |
| Convert an image of any pixel type to another with rounding. | |
| vil3d_image_view_base_sptr | vil3d_convert_to_grey_using_average (const vil3d_image_view_base_sptr &src) |
| Create a greyscale image of specified pixel type from any image src. | |
| vil3d_image_view_base_sptr | vil3d_convert_to_n_planes (unsigned n_planes, const vil3d_image_view_base_sptr &src) |
| Create an n plane image from any image src. | |
| template<class outP> | |
| vil3d_image_view_base_sptr | vil3d_convert_stretch_range (outP, const vil3d_image_view_base_sptr &src) |
| Create an image of the desired type by stretching the range to fit. | |
| #define macro | ( | F, | |||
| T | ) |
Value:
case F: { \ vil3d_image_view<T> src_ref = src; \ if (!src_ref) return vil3d_image_view_base_sptr(); \ vil3d_convert_stretch_range(src_ref, inter, lo, hi); \ vil3d_convert_cast(inter, dest_ref); \ break; }
| #define macro | ( | F, | |||
| T | ) |
Value:
case F: { \ vil3d_image_view<T > src_ref = src; \ if (!src_ref) return vil3d_image_view_base_sptr(); \ /* try to do it quickly 1 */ \ if (src_ref.nplanes() >= n_planes) /* reduce number of planes */ \ return vil3d_image_view_base_sptr( new vil3d_image_view<T >( \ vil3d_planes(vil3d_image_view<T > (src),0,1,n_planes) )); \ else { /* expand number of planes with copying */ \ vil3d_image_view_base_sptr dest = new vil3d_image_view<T >( \ src_ref.ni(), src_ref.nj(), src_ref.nk(), n_planes); \ vil3d_image_view<T > & dest_ref = \ static_cast<vil3d_image_view<T > &>(*dest); \ vil3d_image_view<T > dest_slices = \ vil3d_planes(dest_ref, 0, 1, src_ref.nplanes()); \ vil3d_copy_reformat(src_ref, dest_slices); \ vil3d_image_view<T > src_slice(vil3d_plane(src_ref, 0)); \ for (unsigned i=src_ref.nplanes(); i<n_planes; ++i) { \ dest_slices = vil3d_plane(dest_ref, i); \ vil3d_copy_reformat(src_slice, dest_slices); } \ return dest; } } \
| #define macro | ( | F, | |||
| T | ) |
Value:
case F: { \ /* try to do it quickly */ \ if (src->nplanes() == 1 && \ vil_pixel_format_component_format(src->pixel_format())==1) \ return src; \ /* create output view */ \ vil3d_image_view<T > dest; \ vil3d_image_view<T > src1 = *src; \ vil3d_math_mean_over_planes(src1, dest, double()); \ return vil3d_image_view_base_sptr(new vil3d_image_view<T >(dest)); }
| #define macro | ( | F, | |||
| T | ) |
Value:
case F: { \ vil3d_image_view<T > src1 = src; \ vil3d_transform2(src1, dest_ref, vil_convert_round_pixel<T , outP>()); \ break; }
| #define macro | ( | F, | |||
| T | ) |
Value:
case F: \ vil3d_convert_cast( vil3d_image_view<T >( src ), dest_ref );\ break;
| vil3d_image_view_base_sptr vil3d_convert_cast | ( | outP | , | |
| const vil3d_image_view_base_sptr & | src | |||
| ) | [inline] |
Cast the unknown pixel type to the known one.
This function is designed to be used with vil3d_load or vil3d_image_resource::get_view() where you do not know the pixel type in advance. If you need a multi-component view, then call this to get the corresponding multi-planar view, and do a second (cheap) conversion. The input image's storage arrangement may not be preserved.
Definition at line 190 of file vil3d_convert.h.
| vil3d_image_view_base_sptr vil3d_convert_round | ( | outP | , | |
| const vil3d_image_view_base_sptr & | src | |||
| ) | [inline] |
Convert an image of any pixel type to another with rounding.
This should only be used to convert to scalar pixel types. This function only rounds in terms of the destination type. This function is designed to be used with vil3d_load or vil3d_image_resource::get_view() where you do not know the pixel type in advance.
If the input image already has outP as its pixel type, the destination may only be a shallow copy of the source. outP should be a scalar pixel type. The input image's storage arrangement may not be preserved.
Definition at line 234 of file vil3d_convert.h.
| vil3d_image_view_base_sptr vil3d_convert_stretch_range | ( | outP | , | |
| const vil3d_image_view_base_sptr & | src | |||
| ) | [inline] |
Create an image of the desired type by stretching the range to fit.
This function is designed to be used with vil3d_load or vil3d_image_resource::get_view() where you do not know the pixel type in advance. In the case of floating point output pixels the range is set to [0,1] The input image's storage arrangement may not be preserved.
This function works on scalar pixel types only. You can convert the image to rgb using a cheap assignment afterwards.
Definition at line 384 of file vil3d_convert.h.
| void vil3d_convert_stretch_range | ( | const vil3d_image_view< inP > & | src, | |
| vil3d_image_view< double > & | dest, | |||
| double | lo, | |||
| double | hi | |||
| ) | [inline] |
Convert src to double image dest by stretching to range [lo,hi].
Definition at line 132 of file vil3d_convert.h.
| void vil3d_convert_stretch_range_limited | ( | const vil3d_image_view< inP > & | src, | |
| vil3d_image_view< double > & | dest, | |||
| const inP | src_lo, | |||
| const inP | src_hi, | |||
| const double | dest_lo, | |||
| const double | dest_hi | |||
| ) | [inline] |
Convert src image<inP> to dest image<double> by stretching input range [src_lo, src_hi] to output range [dest_lo, dest_hi].
Inputs < src_lo are mapped to dest_lo, and inputs > src_hi to dest_hi.
Definition at line 154 of file vil3d_convert.h.
| vil3d_image_view_base_sptr vil3d_convert_to_grey_using_average | ( | const vil3d_image_view_base_sptr & | src | ) | [inline] |
Create a greyscale image of specified pixel type from any image src.
This function is designed to be used with vil3d_load or vil3d_image_resource::get_view() where you do not know the pixel type in advance. e.g.
vil3d_image_view<float> input = vil3d_convert_cast(
convert_to_grey_using_average(vil3d_load(filename)), float());
Definition at line 281 of file vil3d_convert.h.
| vil3d_image_view_base_sptr vil3d_convert_to_n_planes | ( | unsigned | n_planes, | |
| const vil3d_image_view_base_sptr & | src | |||
| ) | [inline] |
Create an n plane image from any image src.
This function is designed to be used with vil3d_load or vil3d_image_resource::get_view() where you do not know the pixel type or number of planes in advance. If the input images have too many planes, the higher planes will be truncated. If the input image has too few planes, the new planes will be copies of the first plane.
The output may be a shallow copy of the input. The input image's storage arrangement may not be preserved.
Definition at line 327 of file vil3d_convert.h.
1.5.1