From d462ece7c953c731c3e32d499a01b6ddb26eb93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 13 Nov 2023 23:15:34 +0100 Subject: [PATCH] Improve histogram for 8 bit images --- histogram.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index c3ec0ff..a745700 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -40,7 +40,8 @@ void Histogram::paintEvent(QPaintEvent *) uint64_t end =(i+1) * m_histogram.size() / w; for(uint64_t o = start; o < end; o++) sum += m_histogram[o]; - m_points.push_back(sum); + if(start != end) + m_points.push_back(sum); } float scale = *std::max_element(m_points.begin(), m_points.end()); if(m_log) @@ -57,7 +58,7 @@ void Histogram::paintEvent(QPaintEvent *) points.push_back(QPointF(0, h)); for(size_t i = 0; i < m_points.size(); i++) { - points.push_back(QPointF(i, h - m_points[i] * h)); + points.push_back(QPointF((float)i * w / m_points.size(), h - m_points[i] * h)); } points.push_back(QPoint(w, h)); painter.setBrush(Qt::gray);