8#include <QJsonDocument>
27DefectMap::DefectMap() :
QObject()
35bool DefectMap::load(
const QString &filename)
37 QFile input(filename);
46 m_Filename = filename;
48 auto root = doc.object();
50 m_Camera = root[
"camera"].toString();
51 m_Median = root[
"median"].toDouble();
52 m_StandardDeviation = root[
"standardDeviation"].toDouble();
53 m_HotPixelsAggressiveness = root[
"hotAggressiveness"].toInt();
54 m_ColdPixelsAggressiveness = root[
"coldAggressiveness"].toInt();
68 m_HotPixelsCount = m_HotPixels.size();
76 m_ColdPixelsCount = m_ColdPixels.size();
83bool DefectMap::save(
const QString &filename,
const QString &camera)
87 root.
insert(
"camera", camera);
88 root.
insert(
"median", m_Median);
89 root.
insert(
"standardDeviation", m_StandardDeviation);
90 root.
insert(
"hotAggressiveness", m_HotPixelsAggressiveness);
91 root.
insert(
"coldAggressiveness", m_ColdPixelsAggressiveness);
96 for (
const auto &
onePixel : m_HotPixels)
102 for (
const auto &
onePixel : m_ColdPixels)
109 QFile output(filename);
114 m_Filename = filename;
136 m_Median = data->getMedian(0);
137 m_StandardDeviation = data->getStdDev(0);
138 if (m_HotPixels.empty() && m_ColdPixels.empty())
149 return (m_Median + m_StandardDeviation * calculateSigma(
aggressiveness));
157 return (m_Median - m_StandardDeviation * calculateSigma(
aggressiveness));
163void DefectMap::initBadPixels()
168 m_ColdPixels.clear();
171 switch (m_DarkData->dataType())
217 T
const *buffer =
reinterpret_cast<T
const*
>(m_DarkData->getImageBuffer());
218 const uint32_t width = m_DarkData->width();
219 const uint32_t height = m_DarkData->height();
221 const uint32_t maxSize = 500000;
222 uint32_t samples = m_DarkData->samplesPerChannel();
224 if (samples > maxSize)
226 downsample = (
static_cast<double>(samples) / maxSize) + 0.999;
231 for (uint32_t y = 4; y < height - 4; y +=
downsample)
233 for (uint32_t x = 4; x < width - 4; x +=
downsample)
235 uint32_t offset = x + y * width;
237 m_HotPixels.insert(BadPixel(x, y, buffer[offset]));
239 m_ColdPixels.insert(BadPixel(x, y, buffer[offset]));
249void DefectMap::filterPixels()
254 m_HotPixelsThreshold = m_HotPixels.lower_bound(BadPixel(0, 0,
hotPixelThreshold));
257 if (m_HotPixelsThreshold == m_HotPixels.cend())
258 m_HotPixelsCount = 0;
260 m_HotPixelsCount = std::distance(m_HotPixelsThreshold, m_HotPixels.cend());
262 if (m_ColdPixelsThreshold == m_ColdPixels.cbegin())
263 m_ColdPixelsCount = 0;
265 m_ColdPixelsCount = std::distance(m_ColdPixels.cbegin(), m_ColdPixelsThreshold);
267 emit pixelsUpdated(m_HotPixelsCount, m_ColdPixelsCount);
273void DefectMap::setHotEnabled(
bool enabled)
275 m_HotEnabled = enabled;
276 emit pixelsUpdated(m_HotEnabled ? m_HotPixelsCount : 0, m_ColdPixelsCount);
282void DefectMap::setColdEnabled(
bool enabled)
284 m_ColdEnabled = enabled;
285 emit pixelsUpdated(m_HotPixelsCount, m_ColdEnabled ? m_ColdPixelsCount : 0);
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
iterator insert(QLatin1StringView key, const QJsonValue &value)