FLImaging 7.8.25.3
TensorImagesWithMaskLabels.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "TensorImages.h"
6
7#include <atomic>
8#include <bitset>
9
10namespace FLImaging
11{
12 namespace AI
13 {
14 template <typename T>
15 class FL_EXPORT CTensorImagesWithMaskLabels : public CTensorImages<T>
16 {
17 public:
18 CTensorImagesWithMaskLabels();
19
20 CTensorImagesWithMaskLabels(const CTensorImagesWithMaskLabels<T>& tsr, bool bDeepCopy = true);
21
22 virtual ~CTensorImagesWithMaskLabels();
23
24 static const CResult GetClassNumFromImages(const Base::CFLImage* pFli, bool bMaskImage, Base::CFLArray<int32_t>& flaClassNum);
25
26 using CTensorImages<T>::Create;
27 virtual const CResult Create(const std::vector<int64_t>& vctShape, bool bOrderByDesc = true, bool bCudaAllocation = true) override;
28 virtual const CResult Create(const Base::CFLImage* pFli, bool bNormalize = true, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, bool* pBAbort = nullptr) override;
29 virtual const CResult Create(const Base::CFLImage* pFli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod, bool bROIExtraction, bool bNormalize, const Base::CMultiVar<T>& mvBlankColor, ImageProcessing::EInterpolationMethod eInterpolationMethod, CTensorImages<T>::ETilingMode eTilingMode, double f64PreScaleRatio, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex, bool* pBAbort) override;
30 virtual const CResult Create(const Base::CFLImage& fli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, CTensorImages<T>::ETilingMode eTilingMode = CTensorImages<T>::ETilingMode_NoTiling_Fit, double f64PreScaleRatio = 1., bool bMaskFigureLabels = false, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingMaskIndex = nullptr, bool* pBAbort = nullptr);
31 virtual const CResult Create(const Base::CFLImage* pFli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, CTensorImages<T>::ETilingMode eTilingMode = CTensorImages<T>::ETilingMode_NoTiling_Fit, double f64PreScaleRatio = 1., bool bMaskFigureLabels = false, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingMaskIndex = nullptr, bool* pBAbort = nullptr);
32
33 virtual const CResult Create(const wchar_t* pWcFilePath, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., bool bRecursive = false, ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, CTensorImages<T>::ETilingMode eTilingMode = CTensorImages<T>::ETilingMode_NoTiling_Fit, double f64PreScaleRatio = 1.) override;
34
35 virtual const CResult Assign(const CTensor<T>* pTsr, bool bDeepCopy = true) override;
36 virtual const CResult Assign(const CTensorImages<T>* pTsr, bool bDeepCopy = true) override;
37
38 virtual const CResult Assign(const CTensorImagesWithMaskLabels<T>& tsr, bool bDeepCopy = true);
39 virtual const CResult Assign(const CTensorImagesWithMaskLabels<T>* pTsr, bool bDeepCopy = true);
40
41 virtual const CResult Append(const Base::CFLImage* pFli, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, CTensorImages<T>::ETilingMode eTilingMode = CTensorImages<T>::ETilingMode_NoTiling_Fit, double f64PreScaleRatio = 1., std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, bool* pBAbort = nullptr) override;
42
43 virtual const CResult Append(const wchar_t* pWcFilePath, bool bRecursive = false) override;
44
45 using CTensor<T>::GetBinaryData;
46 virtual const CResult GetBinaryData(Base::CFLData* pFldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
47
48 using CTensor<T>::SetBinaryData;
49 virtual const CResult SetBinaryData(const Base::CFLData* pFldBinary, int64_t* pI64Offset = nullptr) override;
50
51 virtual const CResult Clear() override;
52
53 virtual const CResult SetMaskLabelImage(const Base::CFLImage& fliMaskLabelImage);
54 virtual const CResult SetMaskLabelImage(const Base::CFLImage* pFliMaskLabelImage);
55 virtual const Base::CFLImage* GetMaskLabelImage() const;
56
57 virtual const CResult SetBatchParameters(const CTensorImages<T>& tsr) override;
58 virtual const CResult SetBatchParameters(const CTensorImagesWithMaskLabels<T>& tsr);
59
60 virtual CTensorImagesWithMaskLabels<T>& Evaluate() override;
61 virtual CComputationalBase<T>* Clone() const override;
62
63 virtual const CResult Swap(CComputationalBase<T>& cbSwap) override;
64
65 virtual const CResult LoadTensor(const std::vector<int64_t>& vctBatchIndices) override;
66 virtual const CResult CopyMaskLabels(CTensorImagesWithMaskLabels<T>* pTsrOrg, std::vector<int64_t>& vctOrders);
67
68 virtual const Base::CFLImage* GetCurrentMaskLabels() const;
69 virtual const Foundation::CFLFigureArray* GetCurrentMaskFigureLabels() const;
70 virtual const Foundation::CFLFigureArray* GetCurrentMaskFigureBoundaryRectLabels() const;
71
72 virtual const CResult EnableMaskLabelImage(bool bEnable);
73 virtual bool IsMaskLabelImageEnabled() const;
74
75 virtual const CResult EnableMaskTensor(bool bEnable);
76 virtual bool IsMaskTensorEnabled() const;
77
78 virtual const CResult EnableMaskFigureLabels(bool bEnable);
79 virtual bool IsMaskFigureLabelsEnabled() const;
80
81 virtual const CResult CreateLabelImage(const Base::CFLImage* pFliSrc, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod, CTensorImages<T>::ETilingMode eTilingMode, double f64PreScaleRatio, bool bAppend = false, bool bMaskFigureLabels = false, std::atomic<int32_t>* pI32CurrentPreparingMaskIndex = nullptr, bool* pBAbort = nullptr, Base::CFLImage* pFliDst = nullptr, Base::EPixelFormat ePixelForamt = EPixelFormat_C1_F32);
82
83 virtual const CResult GetLabelRatio(std::vector<float>& vctLabelRatio);
84 virtual const CResult GetLabelRatioSum(std::vector<float>& vctLabelRatioSum);
85 virtual const CResult GetLabelCount(std::vector<int32_t>& vctLabelCount);
86
87 virtual const CResult EnableLabelIncludingOutline(bool bEnable);
88 virtual bool IsLabelIncludingOutlineEnabled() const;
89
90 virtual const CResult SetLabelOutlineThickness(float f32Thickness);
91 virtual float GetLabelOutlineThickness() const;
92
93 virtual const CResult SetLabelIncludingContourNum(int32_t i32LabelNum);
94 virtual int32_t GettLabelIncludingContourNum() const;
95
96 virtual const CResult SetZeroLabelFigureConvertNum(int32_t i32LabelNum);
97 virtual int32_t GetZeroLabelFigureConvertNum() const;
98
99 virtual const CResult GetFigureMaskLabels(Foundation::CFLFigureArray& flaResult);
100 virtual const CResult GetFigureBoundaryRectMaskLabels(Foundation::CFLFigureArray& flaResult);
101 virtual const Base::CFLImage* GetMaskLabels() const;
102
103 DeclareGetClassType();
104 SupportToDuplicateObject(CTensorImagesWithMaskLabels, *this);
105
106 protected:
107 virtual const CResult DecodeLabels(const wchar_t* pWcsImagePath, Base::CFLImage* pFli = nullptr);
108 virtual const CResult MakeDistribution() override;
109 virtual const CResult InternalCreateLabelImage(const std::vector<int64_t>& vctBatchIndices, const Base::CFLImage* pFliSrc, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod, bool bAppend = false, bool bMaskFigureLabels = false, std::atomic<int32_t>* pI32CurrentPreparingMaskIndex = nullptr, bool* pBAbort = nullptr, Base::CFLImage* pFliDst = nullptr, Base::EPixelFormat ePixelForamt = EPixelFormat_C1_F32);
110
111 protected:
112 Base::CFLImage* m_pFliMaskLabelImage;
113 Base::CFLImage m_fliMaskLabels;
114 Base::CFLImage m_fliCurrentMaskLabels;
115 Base::CFLImage m_fliMaskLabelThreadBuffer;
116 Foundation::CFLFigureArray m_flfaMaskFigureLabels;
117 Foundation::CFLFigureArray m_flfaMaskFigureBoundaryRectLabels;
118 Foundation::CFLFigureArray m_flfaCurrentMaskFigureBoundaryRectLabels;
119 Foundation::CFLFigureArray m_flfaCurrentMaskFigureLabels;
120
121 std::vector<float>& m_vctLabelRatio;
122 std::vector<float>& m_vctLabelRatioSum;
123 std::vector<int32_t>& m_vctLabelCount;
124
125 std::bitset<1024>& m_bsLabels;
126
127 bool m_bMaskFigureLabels;
128 bool m_bMaskTensor;
129 bool m_bClearMaskLabel;
130 bool m_bMaskImage;
131 bool m_bLabelIncludingOutline;
132 float m_f32LabelIncludingOutlineThickness;
133 int32_t m_i32LabelIncludingContourNum;
134 int32_t m_i32ZeroFigureLabel;
135 int32_t m_i32ZeroLabelFigureConvertNum;
136
137 private:
138 template<typename T>
139 friend class CClassEqualizerBase;
140
141 template<typename T>
142 friend class CClassEqualizerForTensorImagesWithMaskLabels;
143
144 static CTensorImagesWithMaskLabels<T>* GetInstance();
145 public:
146 DeclareGetSignletonObject(CTensorImagesWithMaskLabels);
147 };
148
149 #define CCGFTensorLabelsWithMaskLabels(...) (*(new CTensorImagesWithMaskLabels<float>(__VA_ARGS__)))
150 #define CCGDTensorLabelsWithMaskLabels(...) (*(new CTensorImagesWithMaskLabels<double>(__VA_ARGS__)))
151
152 typedef CTensorImagesWithMaskLabels<float> CTensorImagesWithMaskLabelsF;
153 typedef CTensorImagesWithMaskLabels<double> CTensorImagesWithMaskLabelsD;
154 }
155}
156
157#endif
Definition AlgorithmAIBase.h:18
@ Assign
Set the value of CGUIPropertyItemView3DFigure to the specified figure.
Definition DefinitionsGUIView3D.h:3531
@ Clear
Clear all the figure objects.
Definition DefinitionsGUI.h:5083
@ Append
Load and append.
Definition DefinitionsGUI.h:58