Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <cv.h>
  2. #include <highgui.h>
  3. #include<iostream>
  4. using namespace std;
  5. double getEntropy(IplImage* img);
  6. main()
  7. {
  8.         IplImage *ip=cvLoadImage("junaid.jpg");
  9. /*      cvNamedWindow("Hello",1);
  10.         cvShowImage("Hello",ip);
  11.         cvWaitKey(0);
  12.         */
  13.         getEntropy(ip);
  14. }
  15. double getEntropy(IplImage* img)
  16. {
  17.         double ent=0;
  18.         img=cvLoadImage("junaid.jpg");
  19.         int h,w,c,bins;
  20.         h=img->height; w=img->width; c=img->nChannels;
  21.         bins=256;
  22.  
  23.        
  24.  
  25.         int hSize[]={bins};
  26.         //---- initilize to 0
  27.         for(int i=0;i<bins;i++)
  28.                 hSize[i]=0;
  29.  
  30.  
  31.         //-------- Getting histogram
  32.  
  33.         CvHistogram* hist;
  34.  
  35.         //----------------If image is gray then continues else convert it into grayscale
  36.         IplImage* gray_img=cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, 1 );
  37.         cvCvtColor( img, gray_img, CV_RGB2GRAY );
  38.         //IplImage *ip=cvLoadImage("junaid.jpg");
  39.         cvNamedWindow("Hello",1);
  40.         cvShowImage("Hello",gray_img);
  41.         cvWaitKey(0);
  42.        
  43.         cout<<"X and Y are "<<w<<", "<<h<<endl;
  44.         cvWaitKey(0);
  45.         //--------calculating Histogram
  46.         int x=0;
  47.         CvScalar s;
  48.         for(i=0;i<h;i++)
  49.                 for(int j=0;j<w;j++)
  50.                 {
  51.                        
  52.                         s=cvGet2D(gray_img,i,j);
  53.                         int level=s.val[0];
  54.                         cout<<i<<","<<j<<"= "<<level<<endl;
  55.                         //cout<<level<<"    " <<x++<<endl;
  56.                         //hSize[level]++;
  57.                         cvWaitKey(0);
  58.                 }
  59.        
  60.  
  61.        
  62.        
  63.  
  64.         return ent;
  65. }