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#pragma once
5
6#include <opencv2/core.hpp>
7#include "slideio/imagetools/slideio_imagetools_def.hpp"
8#include "slideio/base/slideio_enums.hpp"
9#include "slideio/imagetools/encodeparameters.hpp"
10
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 SmallImage;
21 class SLIDEIO_IMAGETOOLS_EXPORTS ImageTools
22 {
23 public:
24 struct ImageHeader {
25 int channels = 0;
26 std::vector<int> chanelTypes; // cv types
27 cv::Size size = {};
28 };
29 public:
30 static void readSmallImageRaster(const std::string& path, cv::OutputArray output);
31 static void writeSmallImageRaster(const std::string& path, Compression compression, 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 static void encodeJpegAbbreviated(const cv::Mat& raster, std::vector<uint8_t>& encodedStream, const JpegEncodeParameters& params);
37 static void computeJpegTables(int numChannels, int quality, std::vector<uint8_t>& tablesBlob);
38 // jpeg 2000 related methods
39 static void readJp2KFile(const std::string& path, cv::OutputArray output);
40 static void readBitmap(const std::string& path, cv::OutputArray output);
41 static void readJp2KStremHeader(const uint8_t* data, size_t dataSize, ImageHeader& header);
42 static void decodeJp2KStream(const std::vector<uint8_t>& data, cv::OutputArray output,
43 const std::vector<int>& channelIndices = std::vector<int>(),
44 bool forceYUV = false);
45 static void decodeJp2KStream(const uint8_t* data, size_t dataSize, cv::OutputArray output,
46 const std::vector<int>& channelIndices = std::vector<int>(),
47 bool forceYUV = false);
48 static int encodeJp2KStream(const cv::Mat& mat, uint8_t* buffer, int bufferSize,
49 const JP2KEncodeParameters& parameters);
50 static double computeSimilarity(const cv::Mat& left, const cv::Mat& right, bool ignoreTypes=false);
51 static double computeSimilarity2(const cv::Mat& left, const cv::Mat& right);
52 static double compareHistograms(const cv::Mat& leftM, const cv::Mat& rightM, int bins);
53 static std::shared_ptr<SmallImage> openSmallImage(const std::string& filePath);
54 template <typename Type>
55 static void convertTo32bitChannels(Type* data, int width, int height, int numChannels, int32_t** channels)
56 {
57 const int pixelSize = numChannels;
58 const int stride = pixelSize * width;
59 Type* line = data;
60 int channelShift = 0;
61 for (int y = 0; y < height; ++y) {
62 Type* pixel = line;
63 for (int x = 0; x < width; ++x) {
64 for (int channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
65 int32_t* channel = channels[channelIndex];
66 channel[channelShift] = static_cast<int32_t>(pixel[channelIndex]);
67 }
68 pixel += pixelSize;
69 channelShift++;
70 }
71 line += stride;
72 }
73 }
74 };
75}
Definition: exceptions.hpp:15