MaskDarkAnalysis: Add
This commit is contained in:
@@ -4,7 +4,9 @@ ADD_LIBRARY(JFJochImageAnalysis STATIC
|
||||
MXAnalysisAfterFPGA.h
|
||||
MXAnalysisAfterFPGA.cpp
|
||||
SpotAnalyze.cpp
|
||||
SpotAnalyze.h)
|
||||
SpotAnalyze.h
|
||||
mask_dark_analysis/MaskDarkAnalysis.cpp
|
||||
mask_dark_analysis/MaskDarkAnalysis.h)
|
||||
|
||||
FIND_PACKAGE(Eigen3 3.4 REQUIRED NO_MODULE) # provides Eigen3::Eigen
|
||||
|
||||
|
||||
55
image_analysis/mask_dark_analysis/MaskDarkAnalysis.cpp
Normal file
55
image_analysis/mask_dark_analysis/MaskDarkAnalysis.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "MaskDarkAnalysis.h"
|
||||
#include "../../common/JFJochException.h"
|
||||
|
||||
MaskDarkAnalysis::MaskDarkAnalysis(size_t det_size) : mask(det_size, 0) {}
|
||||
|
||||
template<class T>
|
||||
void MaskDarkAnalysis::check(const T *ptr) {
|
||||
std::unique_lock ul(m);
|
||||
for (int i = 0; i < mask.size(); i++) {
|
||||
auto v64 = static_cast<int64_t>(ptr[i]);
|
||||
if (v64 > max_allowed_value)
|
||||
mask[i]++;
|
||||
}
|
||||
}
|
||||
|
||||
void MaskDarkAnalysis::AnalyzeImage(const DataMessage &data, std::vector<uint8_t> buffer) {
|
||||
if (data.image.GetWidth() * data.image.GetHeight() != mask.size())
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Invalid size of input image");
|
||||
|
||||
auto ptr = data.image.GetUncompressedPtr(buffer);
|
||||
|
||||
switch (data.image.GetMode()) {
|
||||
case CompressedImageMode::Int8:
|
||||
check(reinterpret_cast<const int8_t *>(ptr));
|
||||
break;
|
||||
case CompressedImageMode::Uint8:
|
||||
check(reinterpret_cast<const uint8_t *>(ptr));
|
||||
break;
|
||||
case CompressedImageMode::Int16:
|
||||
check(reinterpret_cast<const int16_t *>(ptr));
|
||||
break;
|
||||
case CompressedImageMode::Uint16:
|
||||
check(reinterpret_cast<const uint16_t *>(ptr));
|
||||
break;
|
||||
case CompressedImageMode::Int32:
|
||||
check(reinterpret_cast<const int32_t *>(ptr));
|
||||
break;
|
||||
case CompressedImageMode::Uint32:
|
||||
check(reinterpret_cast<const uint32_t *>(ptr));
|
||||
break;
|
||||
default:
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "RGB/float image mode not supported");
|
||||
}
|
||||
}
|
||||
|
||||
void MaskDarkAnalysis::ApplyMask(PixelMask &in_mask) const {
|
||||
std::unique_lock ul(m);
|
||||
std::vector<uint32_t> tmp(mask.size(), 0);
|
||||
for (int i = 0; i < mask.size(); i++)
|
||||
tmp[i] = (mask[i] > max_allowed_freq) ? 1 : 0;
|
||||
in_mask.LoadDarkBadPixelMask(tmp);
|
||||
}
|
||||
30
image_analysis/mask_dark_analysis/MaskDarkAnalysis.h
Normal file
30
image_analysis/mask_dark_analysis/MaskDarkAnalysis.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#ifndef JFJOCH_MASKDARKANALYSIS_H
|
||||
#define JFJOCH_MASKDARKANALYSIS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include "../common/CompressedImage.h"
|
||||
#include "../common/PixelMask.h"
|
||||
|
||||
class MaskDarkAnalysis {
|
||||
mutable std::mutex m;
|
||||
|
||||
const int64_t max_allowed_value = 1;
|
||||
const int64_t max_allowed_freq = 10;
|
||||
|
||||
std::vector<uint32_t> mask;
|
||||
|
||||
|
||||
template <class T> void check(const T *ptr);
|
||||
public:
|
||||
explicit MaskDarkAnalysis(size_t det_size);
|
||||
void AnalyzeImage(const DataMessage &msg, std::vector<uint8_t> buffer);
|
||||
void ApplyMask(PixelMask &mask) const;
|
||||
};
|
||||
|
||||
|
||||
#endif //JFJOCH_MASKDARKANALYSIS_H
|
||||
Reference in New Issue
Block a user