v1.0.0-rc.40

This commit is contained in:
2025-05-28 18:49:27 +02:00
parent aaae74e70b
commit 53c90ee5d8
340 changed files with 9583 additions and 5919 deletions

View File

@@ -3,10 +3,9 @@
#include "ImageAnalysisCPU.h"
#include "../common/CUDAWrapper.h"
#include "StrongPixelSet.h"
#include "../compression/JFJochDecompress.h"
#include "indexing/IndexerFactory.h"
ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
const AzimuthalIntegration &in_integration,
@@ -17,7 +16,8 @@ ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
xpixels(experiment.GetXPixelsNum()),
mask_1byte(npixels, 0),
spotFinder(in_integration),
saturation_limit(experiment.GetSaturationLimit()) {
saturation_limit(experiment.GetSaturationLimit()),
integrate(in_experiment) {
nquads = 2;
@@ -26,15 +26,7 @@ ImageAnalysisCPU::ImageAnalysisCPU(const DiffractionExperiment &in_experiment,
for (int i = 0; i < npixels; i++)
mask_1byte[i] = (in_mask[i] != 0);
auto uc = experiment.GetUnitCell();
if (uc && (get_gpu_count() > 0)) {
try {
indexer = std::make_unique<IndexerWrapper>();
indexer->Setup(uc.value());
} catch (const std::exception &e) {
throw JFJochException(JFJochExceptionCategory::GPUCUDAError, e.what());
}
}
indexer = CreateIndexer(experiment);
}
void ImageAnalysisCPU::UpdateROI() {
@@ -44,40 +36,34 @@ void ImageAnalysisCPU::UpdateROI() {
}
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))
if ((output.image.GetWidth() != xpixels)
|| (output.image.GetWidth() * output.image.GetHeight() != npixels))
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Mismatch in pixel size");
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);
const uint8_t *image_ptr = output.image.GetUncompressedPtr(image);
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)
switch (output.image.GetMode()) {
case CompressedImageMode::Int8:
Analyze<int8_t>(output, image_ptr, INT8_MIN, INT8_MAX, profile, spot_finding_settings);
else if (output.image.pixel_depth_bytes == 2)
break;
case CompressedImageMode::Int16:
Analyze<int16_t>(output, image_ptr, INT16_MIN, INT16_MAX, profile, spot_finding_settings);
else if (output.image.pixel_depth_bytes == 4)
break;
case CompressedImageMode::Int32:
Analyze<int32_t>(output, image_ptr, INT32_MIN, INT32_MAX, profile, spot_finding_settings);
} else {
if (output.image.pixel_depth_bytes == 1)
break;
case CompressedImageMode::Uint8:
Analyze<uint8_t>(output, image_ptr, UINT8_MAX, UINT8_MAX, profile, spot_finding_settings);
else if (output.image.pixel_depth_bytes == 2)
break;
case CompressedImageMode::Uint16:
Analyze<uint16_t>(output, image_ptr, UINT16_MAX, UINT16_MAX, profile, spot_finding_settings);
else if (output.image.pixel_depth_bytes == 4)
break;
case CompressedImageMode::Uint32:
Analyze<uint32_t>(output, image_ptr, UINT32_MAX, UINT32_MAX, profile, spot_finding_settings);
break;
default:
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "RGB/float mode not supported");
}
}
@@ -106,6 +92,8 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
auto &corrections = integration.Corrections();
auto nbins = integration.GetBinNumber();
std::vector<int32_t> updated_image(experiment.GetPixelsNum());
std::vector<float> sum(nbins);
std::vector<float> sum2(nbins);
std::vector<uint32_t> count(nbins);
@@ -114,13 +102,18 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
auto bin = pixel_to_bin[i];
auto value = image[i] * corrections[i];
if (mask_1byte[i] != 0)
if (mask_1byte[i] != 0) {
updated_image[i] = INT32_MIN;
++masked_pixels;
else if (image[i] >= sat_pixel_val)
} else if (image[i] >= sat_pixel_val) {
updated_image[i] = INT32_MIN;
++sat_pixels;
else if (std::is_signed<T>::value && (image[i] == err_pixel_val)) // Error pixels are possible only for signed types
} else if (std::is_signed<T>::value && (image[i] == err_pixel_val)) {// Error pixels are possible only for signed types
updated_image[i] = INT32_MIN;
++err_pixels;
else {
} else {
updated_image[i] = static_cast<int32_t>(image[i]);
if (image[i] > max_value)
max_value = image[i];
if (image[i] < min_value)
@@ -163,10 +156,14 @@ void ImageAnalysisCPU::Analyze(DataMessage &output,
for (const auto &spot: spots_out)
output.spots.push_back(spot);
output.indexing_result = false;
if (indexer && spot_finding_settings.indexing)
indexer->Run(output, spots_out, experiment.GetDiffractionGeometry(), spot_finding_settings.indexing_tolerance);
if (indexer && spot_finding_settings.indexing) {
auto latt = indexer->Run(output, spots_out);
if (latt && spot_finding_settings.quick_integration) {
output.reflections = integrate.Integrate(
CompressedImage(updated_image, experiment.GetXPixelsNum(),
experiment.GetYPixelsNum()), latt.value());
}
}
output.max_viable_pixel_value = max_value;
output.min_viable_pixel_value = min_value;