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