Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include "bitmap_image.hpp" // библиотека для изображения
  4.  
  5. using namespace std;
  6. int a[128][128];//массив для хранения изображенимя
  7. int main() {
  8. bitmap_image image("C://al.bmp"); // создаем объект, где хранится изображения
  9. for (int x = 0; x < image.width(); x++) {
  10. for (int y = 0; y < image.height(); y++) {
  11. rgb_t color; // структура color, в которой хранятся значения характеристики цвето
  12. image.get_pixel(x, y, color.blue, color.red, color.green);//получаем значения яркости писеле
  13. a[x][y] = color.red; // значения r g b равны, тк изображение ч/б, поэтому в массив можем записать любой
  14. }
  15. }
  16. int b[261]; // массив, в котором будем считать частоты встречи элементов
  17. for (int i = 0; i < 261; i++)
  18. b[i] = 0; //зануляем его
  19. for (int i = 0; i < 128; i++){
  20. a[i][64] = round (double (a[i][64]) / 20) * 20 ; //округление
  21. b[a[i][64]]++;
  22. cout << a[i][64] << ' '; //выводим среднюю строку
  23. }
  24. cout << endl;
  25. float ent = 0; // значение энтропии
  26. for (int i = 0; i < 261; i++)
  27. { if (b[i] > 0)
  28. { cout << i << ' ' << b[i] << endl; //выводим значение вероятности
  29. ent = ent - (double(b[i]) / 128) * log2(double(b[i]) / 128);
  30. }
  31. }
  32. cout << "ent = " << ent; //выводим значение энтропии
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement