v1.0.0-rc.36
This commit is contained in:
@@ -2,34 +2,32 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "ImageAnalysisCPU.h"
|
||||
#include "../common/AzimuthalIntegrationProfile.h"
|
||||
|
||||
#include "../common/CUDAWrapper.h"
|
||||
#include "StrongPixelSet.h"
|
||||
#include "../compression/JFJochDecompress.h"
|
||||
|
||||
ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionGeometry &geom,
|
||||
const AzimuthalIntegrationSettings &azint_settings,
|
||||
const SpotFindingSettings &spot_finding_settings,
|
||||
const ROIMap &rmap,
|
||||
const std::optional<UnitCell> &uc,
|
||||
const std::vector<uint32_t> &mask,
|
||||
size_t width, size_t height)
|
||||
: geom(geom),
|
||||
rois(rmap),
|
||||
integration(geom, azint_settings, mask, width, height),
|
||||
settings(spot_finding_settings),
|
||||
npixels(width * height),
|
||||
xpixels(width),
|
||||
mask_1byte(npixels, 0),
|
||||
spotFinder(integration) {
|
||||
|
||||
roi_count = rmap.size();
|
||||
roi_map = rmap.GetROIMap(geom, width, height);
|
||||
roi_names = rmap.GetROINameMap();
|
||||
ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
|
||||
const AzimuthalIntegration &in_integration,
|
||||
const std::vector<uint32_t> &in_mask)
|
||||
: experiment(in_experiment),
|
||||
integration(in_integration),
|
||||
npixels(experiment.GetPixelsNum()),
|
||||
xpixels(experiment.GetXPixelsNum()),
|
||||
mask_1byte(npixels, 0),
|
||||
spotFinder(in_integration),
|
||||
predictor(experiment.GetNeuralNetModelPath()),
|
||||
saturation_limit(experiment.GetSaturationLimit()) {
|
||||
|
||||
roi_map = experiment.ExportROIMap();
|
||||
roi_count = experiment.ROI().size();
|
||||
roi_names = experiment.ROI().GetROINameMap();
|
||||
|
||||
for (int i = 0; i < npixels; i++)
|
||||
mask_1byte[i] = (mask[i] != 0);
|
||||
mask_1byte[i] = (in_mask[i] != 0);
|
||||
|
||||
auto uc = experiment.GetUnitCell();
|
||||
if (uc && (get_gpu_count() > 0)) {
|
||||
try {
|
||||
indexer = std::make_unique<IndexerWrapper>();
|
||||
@@ -40,7 +38,7 @@ ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionGeometry &geom,
|
||||
}
|
||||
}
|
||||
|
||||
void ImageAnalysisCPU::Analyze(DataMessage &output, std::vector<uint8_t> &image) {
|
||||
void ImageAnalysisCPU::Analyze(DataMessage &output, std::vector<uint8_t> &image, AzimuthalIntegrationProfile &profile, const SpotFindingSettings &spot_finding_settings) {
|
||||
if ((output.image.xpixel != xpixels)
|
||||
|| (output.image.xpixel * output.image.ypixel != npixels))
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
@@ -57,26 +55,32 @@ void ImageAnalysisCPU::Analyze(DataMessage &output, std::vector<uint8_t> &image)
|
||||
|
||||
if (output.image.pixel_is_signed) {
|
||||
if (output.image.pixel_depth_bytes == 1)
|
||||
Analyze<int8_t>(output, image.data(), INT8_MIN, INT8_MAX);
|
||||
Analyze<int8_t>(output, image.data(), INT8_MIN, INT8_MAX, profile, spot_finding_settings);
|
||||
else if (output.image.pixel_depth_bytes == 2)
|
||||
Analyze<int16_t>(output, image.data(), INT16_MIN, INT16_MAX);
|
||||
Analyze<int16_t>(output, image.data(), INT16_MIN, INT16_MAX, profile, spot_finding_settings);
|
||||
else if (output.image.pixel_depth_bytes == 4)
|
||||
Analyze<int32_t>(output, image.data(), INT32_MIN, INT32_MAX);
|
||||
Analyze<int32_t>(output, image.data(), INT32_MIN, INT32_MAX, profile, spot_finding_settings);
|
||||
} else {
|
||||
if (output.image.pixel_depth_bytes == 1)
|
||||
Analyze<uint8_t>(output, image.data(), UINT8_MAX, UINT8_MAX);
|
||||
Analyze<uint8_t>(output, image.data(), UINT8_MAX, UINT8_MAX, profile, spot_finding_settings);
|
||||
else if (output.image.pixel_depth_bytes == 2)
|
||||
Analyze<uint16_t>(output, image.data(), UINT16_MAX, UINT16_MAX);
|
||||
Analyze<uint16_t>(output, image.data(), UINT16_MAX, UINT16_MAX, profile, spot_finding_settings);
|
||||
else if (output.image.pixel_depth_bytes == 4)
|
||||
Analyze<uint32_t>(output, image.data(), UINT32_MAX, UINT32_MAX);
|
||||
Analyze<uint32_t>(output, image.data(), UINT32_MAX, UINT32_MAX, profile, spot_finding_settings);
|
||||
}
|
||||
}
|
||||
|
||||
AzimuthalIntegrationProfile ImageAnalysisCPU::CreateProfile() const {
|
||||
return AzimuthalIntegrationProfile(integration);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ImageAnalysisCPU::Analyze(DataMessage &output,
|
||||
const uint8_t *in_image,
|
||||
T err_pixel_val,
|
||||
T sat_pixel_val) {
|
||||
T sat_pixel_val,
|
||||
AzimuthalIntegrationProfile &profile,
|
||||
const SpotFindingSettings &spot_finding_settings) {
|
||||
|
||||
auto image = (T *) in_image;
|
||||
|
||||
@@ -88,6 +92,9 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
|
||||
int64_t min_value = INT64_MAX;
|
||||
int64_t max_value = INT64_MIN;
|
||||
|
||||
if (sat_pixel_val > saturation_limit)
|
||||
sat_pixel_val = static_cast<T>(saturation_limit);
|
||||
|
||||
auto &pixel_to_bin = integration.GetPixelToBin();
|
||||
auto &corrections = integration.Corrections();
|
||||
auto nbins = integration.GetBinNumber();
|
||||
@@ -102,9 +109,9 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
|
||||
|
||||
if (mask_1byte[i] != 0)
|
||||
++masked_pixels;
|
||||
else if (image[i] == sat_pixel_val)
|
||||
else if (image[i] >= sat_pixel_val)
|
||||
++sat_pixels;
|
||||
else if (image[i] == err_pixel_val)
|
||||
else if (std::is_signed<T>::value && (image[i] == err_pixel_val)) // Error pixels are possible only for signed types
|
||||
++err_pixels;
|
||||
else {
|
||||
if (image[i] > max_value)
|
||||
@@ -135,12 +142,13 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
|
||||
}
|
||||
}
|
||||
}
|
||||
AzimuthalIntegrationProfile azint_profile(integration);
|
||||
azint_profile.Add(sum, count);
|
||||
|
||||
profile.Clear(integration);
|
||||
profile.Add(sum, count);
|
||||
|
||||
std::vector<DiffractionSpot> spots;
|
||||
if (settings.enable)
|
||||
spots = spotFinder.Run(image, GetSpotFindingSettings());
|
||||
if (spot_finding_settings.enable)
|
||||
spots = spotFinder.Run(image, spot_finding_settings);
|
||||
|
||||
std::vector<DiffractionSpot> spots_out;
|
||||
FilterSpotsByCount(max_spot_count, spots, spots_out);
|
||||
@@ -150,33 +158,28 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
|
||||
|
||||
output.indexing_result = false;
|
||||
|
||||
if (indexer && settings.indexing)
|
||||
indexer->Run(output, spots_out, geom, settings.indexing_tolerance);
|
||||
if (indexer && spot_finding_settings.indexing)
|
||||
indexer->Run(output, spots_out, experiment.GetDiffractionGeometry(), spot_finding_settings.indexing_tolerance);
|
||||
|
||||
output.max_viable_pixel_value = max_value;
|
||||
output.min_viable_pixel_value = min_value;
|
||||
output.error_pixel_count = err_pixels;
|
||||
output.saturated_pixel_count = sat_pixels;
|
||||
output.az_int_profile = azint_profile.GetResult();
|
||||
output.bkg_estimate = azint_profile.GetBkgEstimate(integration.Settings());
|
||||
|
||||
output.az_int_profile = profile.GetResult();
|
||||
output.bkg_estimate = profile.GetBkgEstimate(integration.Settings());
|
||||
if (spot_finding_settings.resolution_estimate)
|
||||
output.resolution_estimate = predictor.Inference(experiment, image);
|
||||
for (const auto &[key, val]: roi_names)
|
||||
output.roi[key] = roi[val];
|
||||
}
|
||||
|
||||
const AzimuthalIntegration &ImageAnalysisCPU::GetAzimuthalIntegration() const {
|
||||
return integration;
|
||||
}
|
||||
|
||||
void ImageAnalysisCPU::FillStartMessage(StartMessage &msg) {
|
||||
msg.rois = rois.ExportMetadata();
|
||||
msg.rois = experiment.ROI().ExportMetadata();
|
||||
msg.az_int_bin_to_q = integration.GetBinToQ();
|
||||
msg.az_int_bin_number = integration.GetBinNumber();
|
||||
msg.max_spot_count = max_spot_count;
|
||||
}
|
||||
|
||||
void ImageAnalysisCPU::SetSpotFindingSettings(const SpotFindingSettings &in_settings) {
|
||||
std::unique_lock ul(spot_finding_settings_mutex);
|
||||
settings = in_settings;
|
||||
}
|
||||
|
||||
SpotFindingSettings ImageAnalysisCPU::GetSpotFindingSettings() const {
|
||||
std::unique_lock ul(spot_finding_settings_mutex);
|
||||
return settings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user