CSE 576 Image Understanding Spring 1995 Adding a New Transformation to the MSVC/C++ Image Application ============================================================= This refers to the program called "Image" which was used for the in-class activity on Friday, April 7. It resides on the shared file server for the Pentium computer lab in Sieg Hall. (This document written by Evan McLain and edited by Steve Tanimoto, 9 April 1995, Updated 12 April 1995 by SLT) Let's say you want to add a new transformation called Snowstorm that turns everything white. This is an in-place unary transformation (unary because only one image is involved, and in-place because pixels do not depend on the previous values of pixels that were changed before them), so we will add our code in the MUnaryInPlaceTransform class. In X1IFORM.CPP, add three functions: TRANSFORMER(Snowstorm8) { CURRENT(lines) = 255; } TRANSFORMER(Snowstorm4) { CURRENT(lines) = 15; } void MUnaryInPlaceTransform::Snowstorm(MImage *pImg) { TRANSFORM_LOOP(Snowstorm8, Snowstorm4); } The functions Snowstorm8 and Snowstorm4 are two versions of the transformation, one for 8-bit images and one for 4-bit images. We use the TRANSFORMER macro to fill in the header information for us, so all we have to do in the function body is set the current byte to white (255). (In the 4-bit version, white is 15.) The member function Snowstorm contains the main transformation loop. The TRANSFORM_LOOP macro takes the names of the 8- and 4-bit versions of the code and defines a standard transformation loop (i.e., for every pixel in the image, do X). Next, add the declaration of Snowstorm in X1IFORM.H: void Snowstorm(MImage *pImg); Now, start App Studio (i.e. File Open IMAGE.RC) and add a new menu item under the Edit menu. Give it a new resource ID like ID_EDIT_SNOWSTORM. Once you've done that, quit App Studio and open ClassWizard. Add a message handler in the CShellView class so that the menu item ID_EDIT_SNOWSTORM calls the function OnEditTransform(). Finally, go into the function Invoke at the top of X1IFORM.CPP and add a new case to the switch statement: case ID_EDIT_SNOWSTORM: Snowstorm(pImg); break; /////////////////////////// A few other notes: The functions defined by the TRANSFORMER macro are declared inline, but they are only expanded inline if the program is compiled in Visual C++'s Release mode. (This is because you can not step through an inline function, which is a problem when debugging.) The function call overhead in Debug mode can be as much as several seconds on large images.