2025-09-22 23:13:28 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-09-25 19:25:17 +02:00
|
|
|
#include <memory>
|
2025-09-22 23:13:28 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
2026-02-08 12:09:02 +01:00
|
|
|
#include "ILog.hpp"
|
|
|
|
|
#include "IPixelariumImage.hpp"
|
2025-09-25 19:25:17 +02:00
|
|
|
#include "libCZI.h"
|
2026-02-08 12:09:02 +01:00
|
|
|
#include "libCZI_Pixels.h"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
struct CvPixelTypeAndSize
|
|
|
|
|
{
|
|
|
|
|
int size{-1};
|
|
|
|
|
int type{-1};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename P>
|
|
|
|
|
[[nodiscard]] constexpr auto GetCVPixelTypeAndSize(P p) noexcept -> CvPixelTypeAndSize
|
|
|
|
|
{
|
|
|
|
|
switch (p)
|
|
|
|
|
{
|
|
|
|
|
case libCZI::PixelType::Gray8:
|
|
|
|
|
return {1, CV_8U};
|
|
|
|
|
case libCZI::PixelType::Gray16:
|
|
|
|
|
return {2, CV_16U};
|
|
|
|
|
case libCZI::PixelType::Bgr24:
|
|
|
|
|
return {3, CV_8UC3};
|
|
|
|
|
case libCZI::PixelType::Bgra32:
|
|
|
|
|
return {4, CV_8UC4};
|
|
|
|
|
case libCZI::PixelType::Gray32:
|
|
|
|
|
return {4, CV_32S};
|
|
|
|
|
case libCZI::PixelType::Gray32Float:
|
|
|
|
|
return {4, CV_32F};
|
|
|
|
|
default:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
2025-09-22 23:13:28 +02:00
|
|
|
|
|
|
|
|
namespace pixelarium::imaging
|
|
|
|
|
{
|
2025-09-26 21:09:51 +02:00
|
|
|
/// @brief An implementation of IImageQuery to work on CZI images.
|
|
|
|
|
/// @note Check the documentation here https://zeiss.github.io/libczi/pages/mainpage.html#czi-in-a-nutshell
|
2025-09-23 21:57:08 +02:00
|
|
|
struct CziParams : public IImageQuery
|
|
|
|
|
{
|
2025-09-26 21:09:51 +02:00
|
|
|
/// @brief A map providing the start coordinate for each dimension in the CZI
|
|
|
|
|
std::unordered_map<libCZI::DimensionIndex, int> dimension_map;
|
2025-09-23 21:57:08 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-26 21:09:51 +02:00
|
|
|
/// @brief Implements support for .czi-images in the realm of IPixelariumImage
|
2026-01-23 23:00:35 +00:00
|
|
|
class PixelariumCzi : public IPixelariumImageCvMat
|
2025-09-22 23:13:28 +02:00
|
|
|
{
|
2025-09-26 21:09:51 +02:00
|
|
|
using Log = pixelarium::utils::log::ILog;
|
2025-10-08 13:00:09 +02:00
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
public:
|
2025-09-26 21:09:51 +02:00
|
|
|
explicit PixelariumCzi(const std::string& uri, const Log& log);
|
2025-09-25 19:25:17 +02:00
|
|
|
~PixelariumCzi()
|
|
|
|
|
{
|
2025-10-08 13:00:09 +02:00
|
|
|
if (this->czi_reader_) this->czi_reader_->Close();
|
2025-09-25 19:25:17 +02:00
|
|
|
}
|
2025-09-22 23:13:28 +02:00
|
|
|
|
|
|
|
|
// IPixelariumImage member implementations
|
|
|
|
|
public:
|
2026-01-23 23:00:35 +00:00
|
|
|
std::optional<cv::Mat> TryGetImage() override;
|
2025-09-22 23:13:28 +02:00
|
|
|
|
2026-01-23 23:00:35 +00:00
|
|
|
std::optional<cv::Mat> TryGetImage(const IImageQuery&) override;
|
2025-09-22 23:13:28 +02:00
|
|
|
|
2026-01-23 23:00:35 +00:00
|
|
|
std::vector<std::optional<cv::Mat>> TryGetImages(const IImageQuery&) override
|
2025-09-22 23:13:28 +02:00
|
|
|
{
|
2025-09-23 21:57:08 +02:00
|
|
|
// ToDo: proper error
|
|
|
|
|
throw std::runtime_error("Not implemented.");
|
2025-09-22 23:13:28 +02:00
|
|
|
}
|
|
|
|
|
|
2026-01-23 23:00:35 +00:00
|
|
|
public:
|
2025-09-22 23:13:28 +02:00
|
|
|
bool Empty() const noexcept override { return this->is_empty_; }
|
|
|
|
|
|
2025-09-25 19:25:17 +02:00
|
|
|
const libCZI::SubBlockStatistics& GetStatistics() const { return this->image_statistics_; }
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
public:
|
2025-10-07 12:18:00 +02:00
|
|
|
const static ImageFileType type_{ImageFileType::kCzi};
|
2025-09-22 23:13:28 +02:00
|
|
|
|
2025-09-26 21:09:51 +02:00
|
|
|
private:
|
2026-01-23 23:00:35 +00:00
|
|
|
std::optional<cv::Mat> SubblockToCvMat(int index);
|
2025-09-26 21:09:51 +02:00
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
private:
|
|
|
|
|
// this should be set by each image getter
|
|
|
|
|
// after a new cv::Mat could be instantiated
|
|
|
|
|
bool is_empty_{true};
|
2025-09-25 19:25:17 +02:00
|
|
|
|
|
|
|
|
libCZI::SubBlockStatistics image_statistics_;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<libCZI::ICZIReader> czi_reader_;
|
2025-09-26 21:09:51 +02:00
|
|
|
|
|
|
|
|
std::unordered_map<libCZI::DimensionIndex, int> dimension_map_;
|
|
|
|
|
|
|
|
|
|
const Log& log_;
|
2025-09-22 23:13:28 +02:00
|
|
|
};
|
|
|
|
|
} // namespace pixelarium::imaging
|