Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. void histogramEqualization(Mat src){
  2. int height = src.rows;
  3. int width = src.cols;
  4. int M = height*width;
  5. int* h = computeHistogram(src);
  6. Mat dest = src.clone();
  7. int L = 255;
  8.  
  9. float* p = (float*) malloc(256 * sizeof(float));
  10. float* pc = (float*) malloc(256 * sizeof(float));
  11. for(int i = 0; i < 256; i++){
  12. p[i] = h[i]/((float)M);
  13. for(int k = 0; k <= i; k++){
  14. pc[i] += p[k];
  15. }
  16. }
  17.  
  18. for(int i = 0; i < height; i++){
  19. for(int j = 0; j < width; j++){
  20. int gout = L*pc[src.at<unsigned char>(i, j)];
  21. dest.at<unsigned char>(i, j) = gout;
  22. }
  23. }
  24. imshow("src", src);
  25. imshow("dest", dest);
  26. showHistogram("srcHist", computeHistogram(src), 256, 500);
  27. showHistogram("destHist", computeHistogram(dest), 256, 500);
  28. waitKey();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement