Guest User

Untitled

a guest
Oct 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. int main(int, char**)
  2. {
  3. Mat gray=imread("Depth_frames_27/Image23.png",0);
  4. namedWindow( "Gray", 1 ); imshow( "Gray", gray );
  5.  
  6. // Initialize parameters
  7. int histSize = 256; // bin size
  8. float range[] = { 0, 255 };
  9. const float *ranges[] = { range };
  10.  
  11. // Calculate histogram
  12. MatND hist;
  13. calcHist( &gray, 1, 0, Mat(), hist, 1, &histSize, ranges, true, false );
  14.  
  15. double minVal=0, maxVal=0;
  16. minMaxLoc(hist, &minVal, &maxVal, 0, 0);
  17. // cout<<"Max:"<<maxVal<<endl;
  18. // cout<<"Min:"<<minVal<<endl;
  19.  
  20. // Show the calculated histogram in command window
  21. double total;
  22. total = gray.rows * gray.cols;
  23. for( int h = 0; h < histSize; h++ )
  24. {
  25. float binVal = hist.at<float>(h);
  26. cout<<" "<<binVal;
  27. }
  28.  
  29. // Plot the histogram
  30. int hist_w = 512; int hist_h = 400;
  31. int bin_w = cvRound( (double) hist_w/histSize );
  32.  
  33. Mat histImage( hist_h, hist_w, CV_8UC1, Scalar( 0,0,0) );
  34. normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
  35.  
  36. for( int i = 1; i < histSize; i++ )
  37. {
  38. line( histImage, Point( bin_w*(i-1), hist_h - cvRound(hist.at<float>(i-1)) ) ,
  39. Point( bin_w*(i), hist_h - cvRound(hist.at<float>(i)) ),
  40. Scalar( 255, 0, 0), 2, 8, 0 );
  41. }
  42.  
  43. namedWindow( "Result", 1 ); imshow( "Result", histImage );
  44.  
  45. waitKey();
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment