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 readGDALImage(const std::string& path, cv::OutputArray output);
30 static void writeRGBImage(const std::string& path, Compression compression, cv::Mat raster);
31 static void writeTiffImage(const std::string& path, cv::Mat raster);
32 static void readJxrImage(const std::string& path, cv::OutputArray output);
33 static void decodeJxrBlock(const uint8_t* data, size_t size, cv::OutputArray output);
34 static void decodeJpegStream(const uint8_t* data, size_t size, cv::OutputArray output);
35 static void encodeJpeg(const cv::Mat& raster, std::vector<uint8_t>& encodedStream, const JpegEncodeParameters& params);
36 // jpeg 2000 related methods
37 static void readJp2KFile(const std::string& path, cv::OutputArray output);
38 static void readJp2KStremHeader(const uint8_t* data, size_t dataSize, ImageHeader& header);
39 static void decodeJp2KStream(const std::vector<uint8_t>& data, cv::OutputArray output,
40 const std::vector<int>& channelIndices = std::vector<int>(),
41 bool forceYUV = false);
42 static void decodeJp2KStream(const uint8_t* data, size_t dataSize, cv::OutputArray output,
43 const std::vector<int>& channelIndices = std::vector<int>(),
44 bool forceYUV = false);
45 static int encodeJp2KStream(const cv::Mat& mat, uint8_t* buffer, int bufferSize,
46 const JP2KEncodeParameters& parameters);
47 static double computeSimilarity(const cv::Mat& left, const cv::Mat& right, bool ignoreTypes=false);
48 static double computeSimilarity2(const cv::Mat& left, const cv::Mat& right);
49 static double compareHistograms(const cv::Mat& leftM, const cv::Mat& rightM, int bins);
50 static int dataTypeSize(slideio::DataType dt);
51 template <typename Type>
52 static void convertTo32bitChannels(Type* data, int width, int height, int numChannels, int32_t** channels)
53 {
54 const int pixelSize = numChannels;
55 const int stride = pixelSize * width;
56 Type* line = data;
57 int channelShift = 0;
58 for (int y = 0; y < height; ++y) {
59 Type* pixel = line;
60 for (int x = 0; x < width; ++x) {
61 for (int channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
62 int32_t* channel = channels[channelIndex];
63 channel[channelShift] = static_cast<int32_t>(pixel[channelIndex]);
64 }
65 pixel += pixelSize;
66 channelShift++;
67 }
68 line += stride;
69 }
70 }
71 };
72}
73
74#endif
Definition: exceptions.hpp:12