Skip to content

Commit

Permalink
Add nontrivial Saturation calculation for image quality
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseMckinzie committed Aug 12, 2024
1 parent 6b4b6a8 commit 8dbc2ce
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
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

0 comments on commit 8dbc2ce

Please sign in to comment.