CalImage.h 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include "TeledyneXrayProcessingLib.h"
  3. #include <vector>
  4. template <typename T>
  5. class Image
  6. {
  7. public:
  8. int width;
  9. int height;
  10. std::vector<T> pixels;
  11. Image()
  12. {
  13. this->width = 0;
  14. this->height = 0;
  15. this->pixels.clear();
  16. }
  17. bool Create(int w, int h, bool zero = false)
  18. {
  19. if (w <= 0 || h <= 0)
  20. {
  21. return false;
  22. }
  23. this->width = w;
  24. this->height = h;
  25. this->pixels.resize(w * h);
  26. if (zero)
  27. {
  28. std::fill(this->pixels.begin(), this->pixels.end(), 0);
  29. }
  30. return true;
  31. }
  32. bool Load(std::string fileName)
  33. {
  34. int w = TXP_GetTiffWidth(fileName.c_str());
  35. int h = TXP_GetTiffHeight(fileName.c_str());
  36. return this->Create(w, h) && TXP_ReadTiff(fileName.c_str(), this->pixels.data(), this->width, this->height);
  37. }
  38. bool Save(std::string fileName)
  39. {
  40. return TXP_WriteTiff(fileName.c_str(), this->pixels.data(), this->width, this->height);
  41. }
  42. };