/* Astico2D: Another Simple Tool for Image Computing with OpenCV in 2D https://pageperso.lis-lab.fr/edouard.thiel/Astico2D/ demo1.cpp - example 1 of Astico2D use: - Transformations triggered by the keyboard: '1' to '3' - Display in false colors VGA (0 black, 1 blue, .., 255 white, ..) Usage: $ make demo1 $ ./demo1 [-mag w h] [-thr threshold] [-o image_res] image_src CC BY-SA Edouard.Thiel@univ-amu.fr - 30/07/2023 - v1.1 */ #include "astico2d.hpp" //----------------------- T R A N S F O R M A T I O N S ----------------------- // Place here your image transformations in place of these examples. void transform_horizontal_stripes (cv::Mat &img_int) { CHECK_MAT_TYPE(img_int, CV_32SC1); for (int y = 0; y < img_int.rows; y++) for (int x = 0; x < img_int.cols; x++) { int g = img_int.at(y,x); if (g > 0) { img_int.at(y,x) = y; } } } void transform_vertical_stripes (cv::Mat &img_int) { CHECK_MAT_TYPE(img_int, CV_32SC1); for (int y = 0; y < img_int.rows; y++) for (int x = 0; x < img_int.cols; x++) { int g = img_int.at(y,x); if (g > 0) { img_int.at(y,x) = x; } } } void transform_diagonal_stripes (cv::Mat &img_int) { CHECK_MAT_TYPE(img_int, CV_32SC1); for (int y = 0; y < img_int.rows; y++) for (int x = 0; x < img_int.cols; x++) { int g = img_int.at(y,x); if (g > 0) { img_int.at(y,x) = x+y; } } } //--------------------------- A P P L I C A T I O N --------------------------- class MyApp : public Astico2D { public: // Declare here other members MyApp (int argc, char **argv) : Astico2D (argc, argv) // initialize here your member classes { if (!init_ok) return; // error during initialization // Place here other operations of constructor } void print_keyboard_keys () override { // This prints the default usage Astico2D::print_keyboard_keys (); // Indicate keyboard keys and corresponding transformations std::cout << " 1 draw horizontal stripes\n" " 2 draw vertical stripes\n" " 3 draw diagonal stripes\n" << std::endl; } bool handle_keyboard (char key) override { switch (key) { // Handle here the flags (see demo2 for an example) // Add keys for process_transformations case '1' : case '2' : case '3' : // Memorize the pressed key key_transform = key; // Specify mode M_LEVELS or M_COLORS mode_transform = M_LEVELS; break; default : return false; // key not handled } return true; // key handled } void process_transformations () override { // Call here your transforms depending on key_transform and mode_transform: // - if mode_transform is M_COLORS, you can work directly in img_col, // which has the type CV_8UC3; it will be displayed as is. // - if mode_transform is M_LEVELS, the starting image is the thresholded // image img_int, of type CV_32SC1; at the end, to be displayed, you // need to convert the image in colors in img_col, of type CV_8UC3, // for instance with the help of translate_to_vga_colors. switch (key_transform) { case '1' : transform_horizontal_stripes (img_int); translate_to_vga_colors (img_int, img_col); break; case '2' : transform_vertical_stripes (img_int); translate_to_vga_colors (img_int, img_col); break; case '3' : transform_diagonal_stripes (img_int); translate_to_vga_colors (img_int, img_col); break; } } }; // class MyApp //---------------------------------- M A I N ---------------------------------- int main (int argc, char **argv) { MyApp app (argc, argv); return app.run (); }