Warning, file /education/kstars/Tests/ekos/auxiliary/darkprocessor/testdefects.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021 Jasem Mutlaq
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #include <QTest>
0009 #include <memory>
0010 
0011 #include <QObject>
0012 #include "fitsviewer/fitsdata.h"
0013 #include "ekos/auxiliary/darkprocessor.h"
0014 #include "ekos/auxiliary/defectmap.h"
0015 
0016 // At this point, only the methods in focusalgorithms.h are tested.
0017 
0018 class TestDefects : public QObject
0019 {
0020         Q_OBJECT
0021 
0022     public:
0023         /** @short Constructor */
0024         TestDefects();
0025 
0026         /** @short Destructor */
0027         ~TestDefects() override = default;
0028 
0029     private slots:
0030         void basicTest();
0031 };
0032 
0033 #include "testdefects.moc"
0034 
0035 TestDefects::TestDefects() : QObject()
0036 {
0037 }
0038 
0039 
0040 void TestDefects::basicTest()
0041 {
0042     const QString filename = "../Tests/ekos/auxiliary/darkprocessor/hotpixels.fits";
0043     if (!QFileInfo::exists(filename))
0044         QSKIP(QString("Failed to locate file %1, skipping test.").arg(filename).toLatin1());
0045 
0046     // Load FITS Data
0047     QSharedPointer<FITSData> defectiveData;
0048     defectiveData.reset(new FITSData());
0049     QFuture<bool> result = defectiveData->loadFromFile(filename);
0050     result.waitForFinished();
0051 
0052     if (result.result() == false)
0053         QSKIP("Failed to load image, skipping test.");
0054 
0055     // Get Image Buffer
0056     uint8_t *buffer = defectiveData->getWritableImageBuffer();
0057 
0058     // Inject noise in a couple of places
0059     // 50, 10
0060     buffer[50 + 10 * 100] = 255;
0061     // 80, 80
0062     buffer[80 + 80 * 100] = 255;
0063 
0064     // Look for hot pixels above 200 value
0065     // Crop by 3 pixels on all sides since we need to ignore this region as
0066     // it cannot be cleaned up by the algorithm
0067     QList<QPair<int, int>> hot;
0068     for (int y = 3; y < defectiveData->height() - 3; y++)
0069     {
0070         for (int x = 3; x < defectiveData->width() - 3; x++)
0071         {
0072             if (buffer[x + y * defectiveData->width()] > 200)
0073                 hot << qMakePair(x, y);
0074         }
0075 
0076     }
0077 
0078     // Verify we have 3+2 (injected) = 5 above 200
0079     QVERIFY(hot.size() == 5);
0080 
0081     // Now set the dark frame to the defect map
0082     // It should automatically create a list of hot pixels
0083     QSharedPointer<DefectMap> map;
0084     map.reset(new DefectMap());
0085     map->setDarkData(defectiveData);
0086 
0087     // Now fix the hot pixels
0088     QPointer<Ekos::DarkProcessor> processor = new Ekos::DarkProcessor();
0089     processor->normalizeDefects(map, defectiveData, 0, 0);
0090 
0091     // Verify that the buffer was indeed updated and fixed
0092     for (const auto &onePixel : qAsConst(hot))
0093     {
0094         const int value = onePixel.first + onePixel.second * defectiveData->width();
0095         QVERIFY(buffer[value] < 100);
0096     }
0097 }
0098 
0099 QTEST_GUILESS_MAIN(TestDefects)