1 /* 2 * Copyright (c) 2005-2019 Libor Pecháček. 3 * Copyright 2020 Kai Pastor 4 * 5 * This file is part of CoVe 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef COVE_VECTORIZER_H 22 #define COVE_VECTORIZER_H 23 24 #include <memory> 25 #include <vector> 26 27 #include <QImage> 28 #include <QRgb> 29 30 #include "MapColor.h" 31 32 namespace cove { 33 class ProgressObserver; 34 35 class Vectorizer 36 { 37 public: 38 enum ColorSpace 39 { 40 COLSPC_RGB, 41 COLSPC_HSV 42 }; 43 enum LearningMethod 44 { 45 KOHONEN_CLASSIC, 46 KOHONEN_BATCH 47 }; 48 enum AlphaStrategy 49 { 50 ALPHA_CLASSIC, 51 ALPHA_NEUQUANT 52 }; 53 enum PatternStrategy 54 { 55 PATTERN_RANDOM, 56 PATTERN_NEUQUANT 57 }; 58 enum MorphologicalOperation 59 { 60 EROSION, 61 DILATION, 62 THINNING_ROSENFELD, 63 PRUNING 64 }; 65 66 protected: 67 QImage sourceImage; 68 QImage classifiedImage; 69 QImage bwImage; 70 QImage thinnedBWImage; 71 std::vector<std::shared_ptr<MapColor>> sourceImageColors; 72 std::unique_ptr<MapColor> mc; 73 std::vector<bool> selectedColors; // companion to bwImage 74 int E; 75 double initAlpha, q, minAlpha, p, quality; 76 LearningMethod learnMethod; 77 ColorSpace colorSpace; 78 AlphaStrategy alphaStrategy; 79 PatternStrategy patternStrategy; 80 81 void deleteColorsTable(); 82 83 public: 84 Vectorizer(); 85 Vectorizer(QImage& im); 86 virtual void setClassificationMethod(LearningMethod learnMethod); 87 virtual void setColorSpace(ColorSpace colorSpace); 88 virtual void setP(double p); 89 virtual void setAlphaStrategy(AlphaStrategy alphaStrategy); 90 virtual void setPatternStrategy(PatternStrategy patternStrategy); 91 virtual void setInitAlpha(double initAlpha); 92 virtual void setMinAlpha(double minAlpha); 93 virtual void setQ(double q); 94 virtual void setE(int E); 95 virtual void setNumberOfColors(int nColors); 96 virtual void setInitColors(const std::vector<QRgb>& initColors); 97 virtual bool performClassification(ProgressObserver* progressObserver = nullptr); 98 std::vector<QRgb> getClassifiedColors(); 99 virtual QImage getClassifiedImage(double* qualityPtr = nullptr, 100 ProgressObserver* progressObserver = nullptr); 101 virtual QImage getBWImage(std::vector<bool> selectedColors, 102 ProgressObserver* progressObserver = nullptr); 103 virtual QImage getTransformedImage(MorphologicalOperation mo, 104 ProgressObserver* progressObserver = nullptr); 105 static QImage getTransformedImage(const QImage& bwImage, MorphologicalOperation mo, 106 ProgressObserver* progressObserver = nullptr); 107 }; 108 } // cove 109 110 #endif 111