A Not-So-Simple Transformation
That was pretty good, and we are learning to do more interesting things. In Example 2-4 we chose to allocate a new IplImage
structure, and into this new structure we wrote the
output of a single transformation. As mentioned, we could have applied the transformation in
such a way that the output overwrites the original, but this is not always a good idea. In
particular, some operators do not produce images with the same size, depth, and number of
channels as the input image. Typically, we want to perform a sequence
of operations on some initial image and so produce a chain of transformed images.
In such cases, it is often useful to introduce simple wrapper functions that both allocate the output image and perform the
transformation we are interested in. Consider, for example, the reduction of an image by a
factor of 2 [Rosenfeld80]. In OpenCV this is accomplished by the function cvPyrDown()
, which performs a Gaussian smooth and then removes every other line from an image. This is useful
in a wide variety of important vision algorithms. We can implement the simple function
described in Example 2-5.
Example 2-5. Using cvPyrDown() to create a new image that is half the width and height of the input image
IplImage* doPyrDown( IplImage* in, int filter = IPL_GAUSSIAN_5x5 ) { // Best to make sure input image is divisible by two. // assert( in->width%2 == 0 && in->height%2 == 0 ); IplImage* out = cvCreateImage( cvSize( in->width/2, in->height/2 ), in->depth, ...
Get Learning OpenCV now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.