• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Demonstrate using the 'analyze' process module to compute
3 // image statistics.
4 //
5 // Copyright Bob Friesenhahn, 2003, 2004
6 //
7 // Usage: analyze file...
8 //
9 
10 #include <Magick++.h>
11 #include <iostream>
12 #include <iomanip>
13 #include <list>
14 using namespace std;
15 using namespace Magick;
main(int argc,char ** argv)16 int main(int argc,char **argv)
17 {
18   if ( argc < 2 )
19     {
20       cout << "Usage: " << argv[0] << " file..." << endl;
21       exit( 1 );
22     }
23 
24   // Initialize ImageMagick install location for Windows
25   InitializeMagick(*argv);
26 
27   {
28     std::list<std::string> attributes;
29 
30     attributes.push_back("TopLeftColor");
31     attributes.push_back("TopRightColor");
32     attributes.push_back("BottomLeftColor");
33     attributes.push_back("BottomRightColor");
34     attributes.push_back("filter:brightness:mean");
35     attributes.push_back("filter:brightness:standard-deviation");
36     attributes.push_back("filter:brightness:kurtosis");
37     attributes.push_back("filter:brightness:skewness");
38     attributes.push_back("filter:saturation:mean");
39     attributes.push_back("filter:saturation:standard-deviation");
40     attributes.push_back("filter:saturation:kurtosis");
41     attributes.push_back("filter:saturation:skewness");
42 
43     char **arg = &argv[1];
44     while ( *arg )
45       {
46         string fname(*arg);
47         try {
48           cout << "File: " << fname << endl;
49           Image image( fname );
50 
51           /* Analyze module does not require an argument list */
52           image.process("analyze",0,0);
53 
54           list<std::string>::iterator pos = attributes.begin();
55           while(pos != attributes.end())
56             {
57               cout << "  " << setw(16) << setfill(' ') << setiosflags(ios::left)
58                    << *pos << " = " << image.attribute(*pos) << endl;
59               pos++;
60             }
61         }
62         catch( Exception &error_ )
63           {
64             cout << error_.what() << endl;
65           }
66         ++arg;
67       }
68   }
69 
70   return 0;
71 }
72