Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nontrivial Saturation calculation for image quality #232

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/nyx/features/saturation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ void SaturationFeature::reduce (size_t start, size_t end, std::vector<int>* ptrL
}
}

void SaturationFeature::osized_calculate(LR& r, ImageLoader& imloader) {

// Skip calculation in case of noninformative data
if (r.aux_max == r.aux_min) return;

WriteImageMatrix_nontriv Im0 ("SaturationFeature-osized_calculate-Im0", r.label);
Im0.allocate_from_cloud (r.raw_pixels_NT, r.aabb, false);

std::tie(min_saturation_, max_saturation_) = get_percent_max_pixels_NT(Im0);

save_value(r.fvals);
}

void SaturationFeature::save_value(std::vector<std::vector<double>>& feature_vals) {

feature_vals[(int)FeatureIMQ::MAX_SATURATION][0] = max_saturation_;
Expand Down Expand Up @@ -100,3 +113,40 @@ std::tuple<double, double> SaturationFeature::get_percent_max_pixels(const Image

return std::make_tuple(min_pixel_count / image.size(), max_pixel_count / image.size());
}

std::tuple<double, double> SaturationFeature::get_percent_max_pixels_NT(WriteImageMatrix_nontriv& Im) {

auto min_pixel = Im.get_at(0);
auto max_pixel = Im.get_at(0);

auto width = Im.get_width(),
height = Im.get_height();

for (int row=0; row < height; row++) {
for (int col = 0; col < width; col++)
{
size_t idx = row * width + col;
auto pix = Im.get_at(idx);

if (pix > max_pixel) max_pixel = pix;
if (pix < min_pixel) min_pixel = pix;
}
}

double max_pixel_count = 0;
double min_pixel_count = 0;

for (int row=0; row < height; row++) {
for (int col = 0; col < width; col++)
{
size_t idx = row * width + col;
auto pix = Im.get_at(idx);

if (pix == max_pixel) ++max_pixel_count;
if (pix == min_pixel) ++min_pixel_count;
}
}

return std::make_tuple(min_pixel_count / (width*height), max_pixel_count / (width*height));

}
4 changes: 3 additions & 1 deletion src/nyx/features/saturation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class SaturationFeature : public FeatureMethod
void parallel_process(std::vector<int>& roi_labels, std::unordered_map <int, LR>& roiData, int n_threads);
static void parallel_process_1_batch(size_t firstitem, size_t lastitem, std::vector<int>* ptrLabels, std::unordered_map <int, LR>* ptrLabelData);

//=== Non-trivial ROIs ===
//=== Non-trivial ROIs ===
void osized_add_online_pixel(size_t x, size_t y, uint32_t intensity) {}
void osized_calculate(LR& r, ImageLoader& imloader){};
void osized_calculate(LR& r, ImageLoader& imloader);
static std::tuple<double, double> get_percent_max_pixels_NT(WriteImageMatrix_nontriv& Im);

// Result saver
void save_value(std::vector<std::vector<double>>& feature_vals);
Expand Down
Loading