jfjoch_viewer: Auto foreground comes from integer histogram - it is much faster compared to previous implementation

This commit is contained in:
2025-12-12 15:17:55 +01:00
parent f235346467
commit 01adfa342b
4 changed files with 74 additions and 95 deletions

View File

@@ -8,12 +8,13 @@
#include <queue>
#include <algorithm>
#include <cmath>
JFJochReaderImage::JFJochReaderImage(const DataMessage &in_message,
const std::shared_ptr<const JFJochReaderDataset> &in_dataset)
: message(in_message),
dataset(in_dataset),
image(in_dataset->experiment.GetPixelsNum(), 0){
image(in_dataset->experiment.GetPixelsNum(), 0) {
ProcessInputImage(in_message.image);
message.image = CompressedImage(image, in_dataset->experiment.GetXPixelsNum(),
@@ -124,13 +125,12 @@ void JFJochReaderImage::ProcessInputImage(const void *data, size_t npixel, int64
valid_max = std::max(valid_max, val);
}
valid_count++;
count_histogram.Add(val);
top_pixels_acc.Add(val, static_cast<int32_t>(i));
}
}
// For now: auto-foreground based purely on max valid element
auto_foreground = has_valid ? std::max(1, valid_max) : 10;
auto_foreground = count_histogram.Percentile(99.9).value_or(10);
// Export top pixels (already sorted descending) into the existing vector interface
for (int i = 0; i < top_pixels_acc.Size(); i++) {
@@ -139,12 +139,6 @@ void JFJochReaderImage::ProcessInputImage(const void *data, size_t npixel, int64
}
}
void JFJochReaderImage::CalcAutoContrast() {
// Now simplified: based on max element (valid_max)
auto_foreground = has_valid ? std::max(1, valid_max) : 10;
}
std::optional<std::pair<int32_t, int32_t>> JFJochReaderImage::ValidMinMax() const {
if (!has_valid)
return {};
@@ -200,6 +194,7 @@ void JFJochReaderImage::AddImage(const JFJochReaderImage &other) {
top_pixels_acc.Clear();
top_pixels.clear();
top_pixels.reserve(top_pixels_acc.Capacity());
count_histogram.clear();
for (size_t i = 0; i < image.size(); i++) {
if (image[i] == GAP_PXL_VALUE || other.image[i] == GAP_PXL_VALUE) {
@@ -231,14 +226,13 @@ void JFJochReaderImage::AddImage(const JFJochReaderImage &other) {
valid_max = std::max(valid_max, val);
}
valid_count++;
count_histogram.Add(val);
top_pixels_acc.Add(val, static_cast<int32_t>(i));
}
}
}
// For now: auto-foreground based purely on max valid element
auto_foreground = has_valid ? std::max(1, valid_max) : 10;
auto_foreground = count_histogram.Percentile(99.9).value_or(10);
for (int i = 0; i < top_pixels_acc.Size(); i++) {
const auto &e = top_pixels_acc[i];
@@ -281,3 +275,7 @@ std::shared_ptr<JFJochReaderDataset> JFJochReaderImage::CreateMutableDataset() {
int32_t JFJochReaderImage::GetAutoContrastValue() const {
return auto_foreground;
}
std::vector<float> JFJochReaderImage::GetHistogram() const {
return count_histogram.GetCount();
}