v1.0.0-rc.38

This commit is contained in:
2025-05-12 14:17:24 +02:00
parent 19d6f22136
commit b245967df3
201 changed files with 2380 additions and 1432 deletions

View File

@@ -17,12 +17,11 @@ ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
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();
nquads = 2;
UpdateROI();
for (int i = 0; i < npixels; i++)
mask_1byte[i] = (in_mask[i] != 0);
@@ -38,42 +37,50 @@ ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
}
}
void ImageAnalysisCPU::UpdateROI() {
roi_map = experiment.ExportROIMap();
roi_count = experiment.ROI().size();
roi_names = experiment.ROI().GetROINameMap();
}
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,
"Mismatch in pixel size");
image.resize(output.image.xpixel * output.image.ypixel * output.image.pixel_depth_bytes);
const uint8_t *image_ptr;
if (output.image.algorithm == CompressionAlgorithm::NO_COMPRESSION)
image_ptr = output.image.data;
else {
image.resize(output.image.xpixel * output.image.ypixel * output.image.pixel_depth_bytes);
JFJochDecompressPtr(image.data(),
output.image.algorithm,
output.image.data,
output.image.size,
output.image.xpixel * output.image.ypixel,
output.image.pixel_depth_bytes);
JFJochDecompressPtr(image.data(),
output.image.algorithm,
output.image.data,
output.image.size,
output.image.xpixel * output.image.ypixel,
output.image.pixel_depth_bytes);
image_ptr = image.data();
}
if (output.image.pixel_is_signed) {
if (output.image.pixel_depth_bytes == 1)
Analyze<int8_t>(output, image.data(), INT8_MIN, INT8_MAX, profile, spot_finding_settings);
Analyze<int8_t>(output, image_ptr, 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, profile, spot_finding_settings);
Analyze<int16_t>(output, image_ptr, 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, profile, spot_finding_settings);
Analyze<int32_t>(output, image_ptr, 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, profile, spot_finding_settings);
Analyze<uint8_t>(output, image_ptr, 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, profile, spot_finding_settings);
Analyze<uint16_t>(output, image_ptr, 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, profile, spot_finding_settings);
Analyze<uint32_t>(output, image_ptr, 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,
@@ -167,19 +174,14 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
output.saturated_pixel_count = sat_pixels;
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);
if ((inference_client != nullptr) && spot_finding_settings.resolution_estimate)
output.resolution_estimate = inference_client->Inference(experiment, image, nquads);
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 = 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;
}
ImageAnalysisCPU &ImageAnalysisCPU::NeuralNetInference(NeuralNetInferenceClient *client) {
inference_client = client;
return *this;
}