SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
imagetools.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#ifndef OPENCV_slideio_imagetools_HPP
5#define OPENCV_slideio_imagetools_HPP
6
7#include <opencv2/core.hpp>
8#include "slideio/imagetools/slideio_imagetools_def.hpp"
9#include "slideio/base/slideio_enums.hpp"
10#include "slideio/imagetools/encodeparameters.hpp"
11
12#if defined(WIN32)
13#pragma warning( push )
14#pragma warning(disable:4005)
15#pragma warning( pop )
16#endif
17
18namespace slideio
19{
20 class SLIDEIO_IMAGETOOLS_EXPORTS ImageTools
21 {
22 public:
23 struct ImageHeader {
24 int channels = 0;
25 std::vector<int> chanelTypes; // cv types
26 cv::Size size = {};
27 };
28 public:
29 static void readGDALSubset(const std::string& filePath, cv::OutputArray output);
30 static void readGDALImage(const std::string& path, cv::OutputArray output);
31 static void readGDALImageSubDataset(const std::string& path, int subDatasetIndex, cv::OutputArray output);
32 static void writeRGBImage(const std::string& path, Compression compression, cv::Mat raster);
33 static void writeTiffImage(const std::string& path, cv::Mat raster);
34 static void readJxrImage(const std::string& path, cv::OutputArray output);
35 static void decodeJxrBlock(const uint8_t* data, size_t size, cv::OutputArray output);
36 static void decodeJpegStream(const uint8_t* data, size_t size, cv::OutputArray output);
37 static void encodeJpeg(const cv::Mat& raster, std::vector<uint8_t>& encodedStream, const JpegEncodeParameters& params);
38 // jpeg 2000 related methods
39 static void readJp2KFile(const std::string& path, cv::OutputArray output);
40 static void readJp2KStremHeader(const uint8_t* data, size_t dataSize, ImageHeader& header);
41 static void decodeJp2KStream(const std::vector<uint8_t>& data, cv::OutputArray output,
42 const std::vector<int>& channelIndices = std::vector<int>(),
43 bool forceYUV = false);
44 static void decodeJp2KStream(const uint8_t* data, size_t dataSize, cv::OutputArray output,
45 const std::vector<int>& channelIndices = std::vector<int>(),
46 bool forceYUV = false);
47 static int encodeJp2KStream(const cv::Mat& mat, uint8_t* buffer, int bufferSize,
48 const JP2KEncodeParameters& parameters);
49 static double computeSimilarity(const cv::Mat& left, const cv::Mat& right, bool ignoreTypes=false);
50 static double computeSimilarity2(const cv::Mat& left, const cv::Mat& right);
51 static double compareHistograms(const cv::Mat& leftM, const cv::Mat& rightM, int bins);
52 template <typename Type>
53 static void convertTo32bitChannels(Type* data, int width, int height, int numChannels, int32_t** channels)
54 {
55 const int pixelSize = numChannels;
56 const int stride = pixelSize * width;
57 Type* line = data;
58 int channelShift = 0;
59 for (int y = 0; y < height; ++y) {
60 Type* pixel = line;
61 for (int x = 0; x < width; ++x) {
62 for (int channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
63 int32_t* channel = channels[channelIndex];
64 channel[channelShift] = static_cast<int32_t>(pixel[channelIndex]);
65 }
66 pixel += pixelSize;
67 channelShift++;
68 }
69 line += stride;
70 }
71 }
72 };
73}
74
75#endif
Definition: exceptions.hpp:15