Skip to content

Commit 40f1ea5

Browse files
author
volayaf@gmail.com
committed
started adding pymorph library
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@183 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent 38b3212 commit 40f1ea5

File tree

779 files changed

+42140
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

779 files changed

+42140
-4
lines changed

src/sextante/core/Sextante.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sextante.core.SextanteUtils import SextanteUtils
2424
from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider
2525
from sextante.fusion.FusionAlgorithmProvider import FusionAlgorithmProvider
26+
from sextante.pymorph.PymorphAlgorithmProvider import PymorphAlgorithmProvider
2627

2728
class Sextante:
2829

@@ -86,6 +87,7 @@ def initialize():
8687
Sextante.addProvider(FToolsAlgorithmProvider())
8788
Sextante.addProvider(ModelerOnlyAlgorithmProvider())
8889
Sextante.addProvider(GdalAlgorithmProvider())
90+
Sextante.addProvider(PymorphAlgorithmProvider())
8991
Sextante.addProvider(LasToolsAlgorithmProvider())
9092
if SextanteUtils.isWindows():
9193
Sextante.addProvider(FusionAlgorithmProvider())

src/sextante/fusion/GridSurfaceCreate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from sextante.parameters.ParameterFile import ParameterFile
33
from sextante.fusion.FusionUtils import FusionUtils
44
from sextante.parameters.ParameterNumber import ParameterNumber
5-
from sextante.outputs.OutputRaster import OutputRaster
65
from sextante.parameters.ParameterSelection import ParameterSelection
76
from sextante.fusion.FusionAlgorithm import FusionAlgorithm
7+
from sextante.outputs.OutputFile import OutputFile
88

99
class GridSurfaceCreate(FusionAlgorithm):
1010

@@ -22,7 +22,7 @@ def defineCharacteristics(self):
2222
self.addParameter(ParameterNumber(self.CELLSIZE, "Cellsize", 0, None, 10.0))
2323
self.addParameter(ParameterSelection(self.XYUNITS, "XY Units", self.UNITS))
2424
self.addParameter(ParameterSelection(self.ZUNITS, "Z Units", self.UNITS))
25-
self.addOutput(OutputRaster(self.OUTPUT, "PLANS DTM surface"))
25+
self.addOutput(OutputFile(self.OUTPUT, "PLANS DTM surface"))
2626
self.addAdvancedModifiers()
2727

2828
def processAlgorithm(self, progress):

src/sextante/gdal/GdalUtils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ def getSupportedRasters():
5757

5858
@staticmethod
5959
def getSupportedRasterExtensions():
60-
allexts = []
60+
allexts = ["tif"]
6161
for exts in GdalUtils.getSupportedRasters().values():
6262
for ext in exts:
63-
allexts.append(ext)
63+
if ext not in allexts:
64+
allexts.append(ext)
6465
return allexts
6566

6667
@staticmethod

src/sextante/modeler/ModelerGraphicItem.py

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def activateAlgorithm(self):
5353
if not self.model.activateAlgorithm(self.elementIndex, True):
5454
QtGui.QMessageBox.warning(None, "Could not activate Algorithm",
5555
"The selected algorithm depends on other currently non-active algorithms.\nActivate them them before trying to activate it.")
56+
5657
def removeElement(self):
5758
if isinstance(self.element, Parameter):
5859
if not self.model.removeParameter(self.elementIndex):

src/sextante/pymorph/AlgNames.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
class AlgNames():
3+
4+
names = {}
5+
6+
@staticmethod
7+
def getName(shortname):
8+
if not AlgNames.names:
9+
f = open(os.path.dirname(__file__) + "/algnames.txt")
10+
lines = f.readlines()
11+
for line in lines:
12+
tokens = line.split(":")
13+
AlgNames.names[tokens[0].strip()] = tokens[1].strip()
14+
f.close()
15+
return AlgNames.names[shortname]
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from sextante.script.ScriptAlgorithm import ScriptAlgorithm
2+
from sextante.parameters.ParameterRaster import ParameterRaster
3+
from sextante.outputs.OutputRaster import OutputRaster
4+
from sextante.core.GeoAlgorithm import GeoAlgorithm
5+
from sextante.pymorph.AlgNames import AlgNames
6+
import os
7+
8+
class PymorphAlgorithm(ScriptAlgorithm):
9+
10+
LOAD_LAYER_SCRIPT = "from sextante.gdal.GdalUtils import GdalUtils\n" \
11+
+"from sextante.pymorph.mmorph import datatype\n" \
12+
+"gdal_datatypes={'binary':'Byte','uint8':'Byte','uint16':'UInt16','int32':'Int32'}\n" \
13+
+ "try:\n" \
14+
+ "\tfrom osgeo import gdal\n" \
15+
+ "except ImportError:\n" \
16+
+ "\timport gdal\n" \
17+
+ "gdal.AllRegister()\n" \
18+
+ "img = gdal.Open(input_filename)\n"\
19+
+ "input_array = img.ReadAsArray()\n"
20+
21+
SAVE_LAYER_SCRIPT = "\ndrv = gdal.GetDriverByName(GdalUtils.getFormatShortNameFromFilename(output_filename))\n" \
22+
+ "out = drv.Create(output_filename, img.RasterXSize, img.RasterYSize, 1, gdal.GetDataTypeByName(gdal_datatypes[datatype(output_array)]))\n"\
23+
+ "out.SetGeoTransform( img.GetGeoTransform())\n"\
24+
+ "out.SetProjection( img.GetProjectionRef())\n"\
25+
+ "out.GetRasterBand(1).WriteArray(output_array)"
26+
27+
def getCopy(self):
28+
newone = PymorphAlgorithm(self.descriptionFile)
29+
newone.provider = self.provider
30+
return newone
31+
32+
def getIcon(self):
33+
return GeoAlgorithm.getIcon(self)
34+
35+
def defineCharacteristicsFromFile(self):
36+
ScriptAlgorithm.defineCharacteristicsFromFile(self)
37+
self.parameters.insert(0, ParameterRaster("input_filename", "Input image", False))
38+
self.outputs.append(OutputRaster("output_filename", "Output image"))
39+
self.script = self.LOAD_LAYER_SCRIPT + self.script + self.SAVE_LAYER_SCRIPT
40+
self.name = AlgNames.getName(self.name)
41+
42+
def helpFile(self):
43+
command = os.path.basename(self.descriptionFile)
44+
command = command[:command.rfind(".")].replace("_", "")
45+
filename = os.path.dirname(__file__) + "/html/morph/morph/mm" + command + ".html"
46+
return filename
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
from PyQt4.QtCore import *
3+
from PyQt4.QtGui import *
4+
from sextante.core.AlgorithmProvider import AlgorithmProvider
5+
from sextante.script.WrongScriptException import WrongScriptException
6+
from sextante.core.SextanteLog import SextanteLog
7+
from sextante.gdal.GdalUtils import GdalUtils
8+
from sextante.pymorph.PymorphAlgorithm import PymorphAlgorithm
9+
10+
class PymorphAlgorithmProvider(AlgorithmProvider):
11+
12+
def __init__(self):
13+
AlgorithmProvider.__init__(self)
14+
#self.readAlgNames()
15+
self.createAlgsList()
16+
17+
def scriptsFolder(self):
18+
return os.path.dirname(__file__) + "/scripts"
19+
20+
def getDescription(self):
21+
return "Pymorph (Morphological image processing tools)"
22+
23+
def getName(self):
24+
return "pymorph"
25+
26+
def _loadAlgorithms(self):
27+
self.algs = self.preloadedAlgs
28+
29+
def createAlgsList(self):
30+
self.preloadedAlgs = []
31+
folder = self.scriptsFolder()
32+
for descriptionFile in os.listdir(folder):
33+
if descriptionFile.endswith("py"):
34+
try:
35+
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
36+
alg = PymorphAlgorithm(fullpath)
37+
alg.group = "Algorithms"
38+
self.preloadedAlgs.append(alg)
39+
except WrongScriptException,e:
40+
SextanteLog.addToLog(SextanteLog.LOG_ERROR,e.msg)
41+
42+
def getSupportedOutputRasterLayerExtensions(self):
43+
return GdalUtils.getSupportedRasterExtensions()

src/sextante/pymorph/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import mmorph
2+
import text
3+
from mmorph import *
4+
from text import *
5+
from pymorph_version import __version__
6+
7+
__doc__ = mmorph.__doc__
8+
__all__ = mmorph.__all__ + ['text']

src/sextante/pymorph/algnames.txt

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
add4dilate : Addition for dilation
2+
addm : Addition of two images, with saturation.
3+
areaclose : Area closing
4+
areaopen : Area opening
5+
asf : Alternating Sequential Filtering
6+
asfrec : Reconstructive Alternating Sequential Filtering
7+
binary : Convert a gray-scale image into a binary image
8+
cbisector : N-Conditional bisector.
9+
cdilate : Dilate an image conditionally.
10+
center : Center filter.
11+
cerode : Erode an image conditionally.
12+
closeholes : Close holes of binary and gray-scale images.
13+
close : Morphological closing.
14+
closerec : Closing by reconstruction.
15+
closerecth : Close-by-Reconstruction Top-Hat.
16+
closeth : Closing Top Hat.
17+
cthick : Image transformation by conditional thickening.
18+
cthin : Image transformation by conditional thinning.
19+
cwatershed : Detection of watershed from markers.
20+
datatype : Return the image datatype string
21+
dilate : Dilate an image by a structuring element.
22+
dist : Distance transform.
23+
endpoints : Interval to detect end-points.
24+
erode : Erode an image by a structuring element.
25+
flood : Flooding filter- h,v,a-basin and dynamics (depth, area, volume)
26+
gdist : Geodesic Distance Transform.
27+
gradm : Morphological gradient.
28+
hmax : Remove peaks with contrast less than h.
29+
hmin : Remove basins with contrast less than h.
30+
homothick : Interval for homotopic thickening.
31+
homothin : Interval for homotopic thinning.
32+
infcanon : Intersection of inf-generating operators.
33+
infgen : Inf-generating.
34+
infrec : Inf-reconstruction.
35+
inpos : Minima imposition.
36+
interot : Rotate an interval
37+
intersec : Intersection of images.
38+
isolines : Apply an iso-line color table to a gray-scale image.
39+
label : Label a binary image.
40+
labelflat : Label the flat zones of gray-scale images.
41+
lastero : Last erosion.
42+
neg : Negate an image.
43+
open : Morphological opening.
44+
openrec : Opening by reconstruction.
45+
openrecth : Open-by-Reconstruction Top-Hat.
46+
openth : Opening Top Hat.
47+
opentransf : Open transform.
48+
patspec : Pattern spectrum (also known as granulometric size density).
49+
randomcolor : Apply a random color table to a gray-scale image.
50+
regmax : Regional Maximum.
51+
regmin : Regional Minimum (with generalized dynamics).
52+
skelm : Morphological skeleton (Medial Axis Transform).
53+
skelmrec : Morphological skeleton reconstruction (Inverse Medial Axis Transform).
54+
skiz : Skeleton of Influence Zone - also know as Generalized Voronoi Diagram
55+
subm : Subtraction of two images, with saturation.
56+
supcanon : Union of sup-generating or hit-miss operators.
57+
supgen : Sup-generating (hit-miss).
58+
suprec : Sup-reconstruction.
59+
symdiff : Symmetric difference between two images
60+
text : Create a binary image of a text.
61+
thick : Image transformation by thickening.
62+
thin : Image transformation by thinning.
63+
threshad : Threshold (adaptive)
64+
toggle : Image contrast enhancement or classification by the toggle operator.
65+
union : Union of images.
66+
watershed : Watershed detection.

0 commit comments

Comments
 (0)