support_openslide.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 1.0.3
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #ifndef SUPPORT_OPENSLIDE_H_
15 #define SUPPORT_OPENSLIDE_H_
16 
17 #include "ecvl/core/filesystem.h"
18 #include "ecvl/core/image.h"
19 #include "openslide.h"
20 
21 namespace ecvl
22 {
24 {
25  openslide_t* osr_;
26  const ecvl::filesystem::path filename_;
27  int n_levels_;
28 
29 public:
30  OpenSlideImage(const ecvl::filesystem::path& filename) : filename_{ filename }
31  {
32  osr_ = openslide_open(filename.string().c_str());
33  if (osr_ == NULL || openslide_get_error(osr_) != NULL) {
35  }
36  n_levels_ = openslide_get_level_count(osr_);
37  }
38 
40  int GetLevelCount() { return n_levels_; }
41 
47  void GetLevelsDimensions(std::vector<std::array<int, 2>>& levels);
48 
53  void GetLevelDownsamples(std::vector<double>& levels);
54 
61  int GetBestLevelForDownsample(const double& downsample);
62 
67  void GetProperties(Image& dst);
68 
84  bool ReadRegion(Image& dst, const int level, const std::vector<int>& dims);
85 
87  void Close()
88  {
89  openslide_close(osr_);
90  osr_ = nullptr;
91  }
92 
94  {
95  if (osr_) {
96  Close();
97  }
98  }
99 };
100 
104 } // namespace ecvl
105 
106 #endif // SUPPORT_OPENSLIDE_H_
Image class.
Definition: image.h:66
int GetBestLevelForDownsample(const double &downsample)
Get the best level to use for displaying the given downsample.
#define ECVL_ERROR_CANNOT_LOAD_IMAGE
bool ReadRegion(Image &dst, const int level, const std::vector< int > &dims)
Loads a region of a whole-slide image.
void GetLevelsDimensions(std::vector< std::array< int, 2 >> &levels)
Get width and height for each level of a whole-slide image.
void Close()
Close the OpenSlide object.
Definition: any.h:69
int GetLevelCount()
Get the number of levels in the image.
void GetProperties(Image &dst)
Loads properties (metadata) from the OpenSlide file and saves them into an ECVL Image.
OpenSlideImage(const ecvl::filesystem::path &filename)
void GetLevelDownsamples(std::vector< double > &levels)
Get the downsampling factor for each level, or -1.0 if an error occurred.