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