File indexing completed on 2024-04-14 14:10:35

0001 /*
0002     SPDX-FileCopyrightText: 2004 Jasem Mutlaq
0003     SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 
0007     Some code fragments were adapted from Peter Kirchgessner's FITS plugin
0008     SPDX-FileCopyrightText: Peter Kirchgessner <http://members.aol.com/pkirchg>
0009 */
0010 
0011 #ifndef FITSGRADIENTDETECTOR_H
0012 #define FITSGRADIENTDETECTOR_H
0013 
0014 #include "fitsstardetector.h"
0015 
0016 class FITSGradientDetector: public FITSStarDetector
0017 {
0018         Q_OBJECT
0019 
0020     public:
0021         explicit FITSGradientDetector(FITSData * data): FITSStarDetector(data) {};
0022 
0023     public:
0024         /** @brief Find sources in the parent FITS data file.
0025          * @see FITSStarDetector::findSources().
0026          */
0027         QFuture<bool> findSources(QRect const &boundary = QRect()) override;
0028 
0029     protected:
0030         /** @internal Find sources in the parent FITS data file, dependent of the pixel depth.
0031          * @see FITSGradientDetector::findSources.
0032          */
0033         template <typename T>
0034         bool findSources(const QRect &boundary);
0035 
0036         /** @internal Implementation of the Canny Edge detection (CannyEdgeDetector).
0037          * @copyright 2015 Gonzalo Exequiel Pedone (https://github.com/hipersayanX/CannyDetector).
0038          * @param data is the FITS data to run the detection onto.
0039          * @param gradient is the vector storing the amount of change in pixel sequences.
0040          * @param direction is the vector storing the four directions (horizontal, vertical and two diagonals) the changes stored in 'gradient' are detected in.
0041          */
0042         template <typename T>
0043         void sobel(FITSData const * data, QVector<float> &gradient, QVector<float> &direction) const;
0044 
0045         /** @internal Identify gradient connections.
0046          * @param width, height are the dimensions of the frame to work on.
0047          * @param gradient is the vector holding the amount of change in pixel sequences.
0048          * @param ids is the vector storing which gradient was identified for each pixel.
0049          */
0050         int partition(int width, int height, QVector<float> &gradient, QVector<int> &ids) const;
0051 
0052         /** @internal Trace gradient neighbors.
0053          * @param width, height are the dimensions of the frame to work on.
0054          * @param image is the image to work on, actually gradients extracted using the sobel algorithm.
0055          * @param ids is the vector storing which gradient was identified for each pixel.
0056          * @param x, y locate the pixel to trace from.
0057          */
0058         void trace(int width, int height, int id, QVector<float> &image, QVector<int> &ids, int x, int y) const;
0059 };
0060 
0061 #endif // FITSGRADIENTDETECTOR_H