From 613092f3ee214f941f634b4ac50cf21d8fbd7c83 Mon Sep 17 00:00:00 2001 From: Sascha Nitsch Date: Wed, 19 Jan 2022 18:35:25 +0100 Subject: [PATCH] fixed bit masking changed distance calculation --- c++/algorithm/distancepath.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c++/algorithm/distancepath.cpp b/c++/algorithm/distancepath.cpp index 8ad90d4..9ecfb1e 100644 --- a/c++/algorithm/distancepath.cpp +++ b/c++/algorithm/distancepath.cpp @@ -35,8 +35,8 @@ DistancePath::~DistancePath() { inline void DistancePath::processPixel(uint8_t* inRAW, float* outRow, uint16_t x, uint16_t y, float lastValue, uint16_t width, std::list* next, uint16_t* outPixels, uint16_t iteration) { float *oR = &outRow[x]; uint32_t offset = (y * width + x) * 3; - float avg = 255 - (0.3333 * (inRAW[offset] + inRAW[offset + 1] + inRAW[offset + 2])); - float newValue = lastValue + avg * m_weightBlock + (255.0 - avg) * m_weightPath; + float avg = (inRAW[offset] + inRAW[offset + 1] + inRAW[offset + 2]) / 765.0; + float newValue = lastValue + (1.0 - avg) * (m_weightBlock - m_weightPath) + m_weightPath; if (newValue > m_maxDistance) newValue = m_maxDistance; if (newValue < *oR) { next->push_back((x << 16) + y); @@ -72,7 +72,7 @@ int8_t DistancePath::process(Image* input, Image* output) { uint16_t* outPixels = output->getPixels16(); for (uint32_t coordinate : m_queue1) { uint16_t x = coordinate >> 16; - uint16_t y = coordinate & 0xFFFFFFFF; + uint16_t y = coordinate & 0xFFFF; outRAW[(width * y + x)] = 0; } uint16_t iteration = 1; @@ -80,7 +80,7 @@ int8_t DistancePath::process(Image* input, Image* output) { // process pixel from last time for (uint32_t coordinate : *last) { uint16_t x = coordinate >> 16; - uint16_t y = coordinate & 0xFFFFFFFF; + uint16_t y = coordinate & 0xFFFF; float lastValue = outRAW[y * width + x]; if (y > 0) { // process row on top processRow(inRAW, outRAW, x, y-1, lastValue, width, next, outPixels, iteration);