Pawel Netzel - software
Repositories
Help
Report an Issue
plTools
Code
Commits
Branches
Tags
Search
Tree:
4dc058b
Branches
Tags
master
plTools
plTools_plugin
algo_plgeoadaptels.py
plugin bug fixed
netzel
commited
4dc058b
at 2024-03-26 16:32:26
algo_plgeoadaptels.py
Blame
History
Raw
# -*- coding: utf-8 -*- """ /*************************************************************************** plTools A QGIS plugin The plugin adds a set of algorithms from plTools Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ ------------------- begin : 2024-01-10 copyright : (C) 2024 by Pawel Netzel email : pawel@netzel.pl ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ """ __author__ = 'Pawel Netzel' __date__ = '2024-01-10' __copyright__ = '(C) 2024 by Pawel Netzel' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' from qgis.PyQt.QtCore import QCoreApplication from qgis.core import (QgsProcessing, QgsProcessingAlgorithm, QgsProcessingException, QgsProcessingParameterNumber, QgsProcessingParameterEnum, QgsProcessingParameterBoolean, QgsProcessingParameterRasterDestination, QgsProcessingParameterMultipleLayers) from .algo_base import plToolsBaseAlgorithm class adaptels_Algorithm(plToolsBaseAlgorithm): COMMAND = 'plgeoadaptels' OUTPUT = 'OUTPUT' INPUTS = 'INPUTS' DISTANCE = 'DISTANCE' MINKOWSKI = 'MINKOWSKI' THRESHOLD = 'THRESHOLD' NORMALIZE = 'NORMALIZE' QUEENTOPO = 'QUEENTOPO' def initAlgorithm(self, config): super().initAlgorithm(config) self.DIST = ['minkowski','cosine','angular'] self.addParameter(QgsProcessingParameterMultipleLayers(self.INPUTS,self.tr('Input raster layers'),QgsProcessing.TypeRaster)) self.addParameter(QgsProcessingParameterBoolean(self.NORMALIZE,self.tr('Normalize input layers to [0, 1]'),defaultValue=False)) self.addParameter(QgsProcessingParameterEnum(self.DISTANCE,self.tr('Distance'),self.DIST,defaultValue=0, allowMultiple=False)) self.addParameter(QgsProcessingParameterNumber(self.MINKOWSKI,self.tr('Minkowski p'),type=QgsProcessingParameterNumber.Double,defaultValue=2.0, optional=True)) self.addParameter(QgsProcessingParameterNumber(self.THRESHOLD,self.tr('Energy threshold'),type=QgsProcessingParameterNumber.Double,defaultValue=60.0, optional=True)) self.addParameter(QgsProcessingParameterBoolean(self.QUEENTOPO,self.tr('Eight directional merging'),defaultValue=False)) self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,self.tr('GeoAdaptels layer'))) def processAlgorithm(self, parameters, context, feedback): arguments = [self.COMMAND] inputs = self.parameterAsLayerList(parameters, self.INPUTS, context) if inputs is not None: for layer in inputs: arguments.append('-i') arguments.append(layer.source()) normalize = self.parameterAsBoolean(parameters, self.NORMALIZE, context) if normalize: arguments.append('-n') queen = self.parameterAsBoolean(parameters, self.QUEENTOPO, context) if queen: arguments.append('-8') dist = self.parameterAsEnum(parameters, self.DISTANCE, context) if dist: arguments.append('-d') arguments.append(self.DIST[dist]) minkowski = self.parameterAsDouble(parameters, self.MINKOWSKI, context) if minkowski: arguments.append('-p') arguments.append(str(minkowski)) thresh = self.parameterAsDouble(parameters, self.THRESHOLD, context) if thresh: arguments.append('-t') arguments.append(str(thresh)) output = self.parameterAsOutputLayer(parameters,self.OUTPUT,context) arguments.append('-o') arguments.append(output) self.runplTools(arguments, feedback) return {self.OUTPUT: output} def name(self): return 'GeoAdaptels - spatial superpixels' def groupId(self): return '' def createInstance(self): return adaptels_Algorithm() def shortHelpString(self): return ''' plGeoAdaptels is an implementation of an algorithm for creating multi-scale superpixels. This algorithm is described in the <a href="https://doi.org/10.2352/ISSN.2169-2629.2018.26.1">paper</a>. The module uses the authors' code implementation modified to operate on geospatial layers, use four- and eight-way topology, and perform data normalization. For layers representing an image's R, G and B components, the program can optionally perform transformations to CIELAB color space. '''