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
13#if defined(WIN32)
14#pragma warning( push )
15#pragma warning(disable:4005)
16#pragma warning( pop )
17#endif
18
19namespace slideio
20{
21 class SmallImage;
22 class SLIDEIO_IMAGETOOLS_EXPORTS ImageTools
23 {
24 public:
25 struct ImageHeader {
26 int channels = 0;
27 std::vector<int> chanelTypes; // cv types
28 cv::Size size = {};
29 };
30 public:
31 static void readSmallImageRaster(const std::string& path, cv::OutputArray output);
32 static void writeSmallImageRaster(const std::string& path, Compression compression, cv::Mat raster);
33 static void readJxrImage(const std::string& path, cv::OutputArray output);
34 static void decodeJxrBlock(const uint8_t* data, size_t size, cv::OutputArray output);
35 static void decodeJpegStream(const uint8_t* data, size_t size, cv::OutputArray output);
36 static void encodeJpeg(const cv::Mat& raster, std::vector<uint8_t>& encodedStream, const JpegEncodeParameters& params);
37 // jpeg 2000 related methods
38 static void readJp2KFile(const std::string& path, cv::OutputArray output);
39 static void readBitmap(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 static std::shared_ptr<SmallImage> openSmallImage(const std::string& filePath);
53 template <typename Type>
54 static void convertTo32bitChannels(Type* data, int width, int height, int numChannels, int32_t** channels)
55 {
56 const int pixelSize = numChannels;
57 const int stride = pixelSize * width;
58 Type* line = data;
59 int channelShift = 0;
60 for (int y = 0; y < height; ++y) {
61 Type* pixel = line;
62 for (int x = 0; x < width; ++x) {
63 for (int channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
64 int32_t* channel = channels[channelIndex];
65 channel[channelShift] = static_cast<int32_t>(pixel[channelIndex]);
66 }
67 pixel += pixelSize;
68 channelShift++;
69 }
70 line += stride;
71 }
72 }
73 };
74}
75
76#endif
Definition: exceptions.hpp:15