MCPcopy Create free account
hub / github.com/GreycLab/CImg / main

Function main

examples/tutorial.cpp:54–133  ·  view source on GitHub ↗

Main procedure ----------------

Source from the content-addressed store, hash-verified

52// Main procedure
53//----------------
54int main(int argc,char **argv) {
55
56 // Define program usage and read command line parameters
57 //-------------------------------------------------------
58
59 // Display program usage, when invoked from the command line with option '-h'.
60 cimg_usage("View the color profile of an image along the X axis");
61
62 // Read image filename from the command line (or set it to "img/parrot.ppm" if option '-i' is not provided).
63 const char* file_i = cimg_option("-i",cimg_imagepath "parrot.ppm","Input image");
64
65 // Read pre-blurring variance from the command line (or set it to 1.0 if option '-blur' is not provided).
66 const double sigma = cimg_option("-blur",1.0,"Variance of gaussian pre-blurring");
67
68 // Init variables
69 //----------------
70
71 // Load an image, transform it to a color image (if necessary) and blur it with the standard deviation sigma.
72 const CImg<unsigned char> image = CImg<>(file_i).normalize(0,255).blur((float)sigma).resize(-100,-100,1,3);
73
74 // Create two display window, one for the image, the other for the color profile.
75 CImgDisplay
76 main_disp(image,"Color image (Try to move mouse pointer over)",0),
77 draw_disp(500,400,"Color profile of the X-axis",0);
78
79 // Define colors used to plot the profile, and a hatch to draw the vertical line
80 unsigned int hatch = 0xF0F0F0F0;
81 const unsigned char
82 red[] = { 255,0,0 },
83 green[] = { 0,255,0 },
84 blue [] = { 0,0,255 },
85 black[] = { 0,0,0 };
86
87 // Enter event loop. This loop ends when one of the two display window is closed or
88 // when the keys 'ESC' or 'Q' are pressed.
89 while (!main_disp.is_closed() && !draw_disp.is_closed() &&
90 !main_disp.is_keyESC() && !draw_disp.is_keyESC() && !main_disp.is_keyQ() && !draw_disp.is_keyQ()) {
91
92 // Handle display window resizing (if any)
93 if (main_disp.is_resized()) main_disp.resize().display(image);
94 draw_disp.resize();
95
96 if (main_disp.mouse_x()>=0 && main_disp.mouse_y()>=0) { // Mouse pointer is over the image
97
98 const int
99 xm = main_disp.mouse_x(), // X-coordinate of the mouse pointer over the image
100 ym = main_disp.mouse_y(), // Y-coordinate of the mouse pointer over the image
101 xl = xm*draw_disp.width()/main_disp.width(), // Corresponding X-coordinate of the hatched line
102 x = xm*image.width()/main_disp.width(), // Corresponding X-coordinate of the pointed pixel in the image
103 y = ym*image.height()/main_disp.height(); // Corresponding Y-coordinate of the pointex pixel in the image
104
105 // Retrieve color component values at pixel (x,y)
106 const unsigned int
107 val_red = image(x,y,0),
108 val_green = image(x,y,1),
109 val_blue = image(x,y,2);
110
111 // Create and display the image of the intensity profile

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected