Skip to content
Browse files
started adding pymorph library
git-svn-id: 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information committed May 17, 2012
1 parent 38b3212 commit 40f1ea53495cce3ca3b5d08745e111f4b3f5aa2f
Showing 779 changed files with 42,140 additions and 4 deletions.
@@ -23,6 +23,7 @@
from sextante.core.SextanteUtils import SextanteUtils
from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider
from sextante.fusion.FusionAlgorithmProvider import FusionAlgorithmProvider
from sextante.pymorph.PymorphAlgorithmProvider import PymorphAlgorithmProvider

class Sextante:

@@ -86,6 +87,7 @@ def initialize():
if SextanteUtils.isWindows():
@@ -2,9 +2,9 @@
from sextante.parameters.ParameterFile import ParameterFile
from sextante.fusion.FusionUtils import FusionUtils
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.outputs.OutputRaster import OutputRaster
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.fusion.FusionAlgorithm import FusionAlgorithm
from sextante.outputs.OutputFile import OutputFile

class GridSurfaceCreate(FusionAlgorithm):

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

def processAlgorithm(self, progress):
@@ -57,10 +57,11 @@ def getSupportedRasters():

def getSupportedRasterExtensions():
allexts = []
allexts = ["tif"]
for exts in GdalUtils.getSupportedRasters().values():
for ext in exts:
if ext not in allexts:
return allexts

@@ -53,6 +53,7 @@ def activateAlgorithm(self):
if not self.model.activateAlgorithm(self.elementIndex, True):
QtGui.QMessageBox.warning(None, "Could not activate Algorithm",
"The selected algorithm depends on other currently non-active algorithms.\nActivate them them before trying to activate it.")

def removeElement(self):
if isinstance(self.element, Parameter):
if not self.model.removeParameter(self.elementIndex):
@@ -0,0 +1,15 @@
import os
class AlgNames():

names = {}

def getName(shortname):
if not AlgNames.names:
f = open(os.path.dirname(__file__) + "/algnames.txt")
lines = f.readlines()
for line in lines:
tokens = line.split(":")
AlgNames.names[tokens[0].strip()] = tokens[1].strip()
return AlgNames.names[shortname]
@@ -0,0 +1,47 @@
from sextante.script.ScriptAlgorithm import ScriptAlgorithm
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.outputs.OutputRaster import OutputRaster
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.pymorph.AlgNames import AlgNames
import os

class PymorphAlgorithm(ScriptAlgorithm):

LOAD_LAYER_SCRIPT = "from sextante.gdal.GdalUtils import GdalUtils\n" \
+"from sextante.pymorph.mmorph import datatype\n" \
+"gdal_datatypes={'binary':'Byte','uint8':'Byte','uint16':'UInt16','int32':'Int32'}\n" \
+ "try:\n" \
+ "\tfrom osgeo import gdal\n" \
+ "except ImportError:\n" \
+ "\timport gdal\n" \
+ "gdal.AllRegister()\n" \
+ "img = gdal.Open(input_filename)\n"\
+ "input_array = img.ReadAsArray()\n"

SAVE_LAYER_SCRIPT = "\ndrv = gdal.GetDriverByName(GdalUtils.getFormatShortNameFromFilename(output_filename))\n" \
+ "out = drv.Create(output_filename, img.RasterXSize, img.RasterYSize, 1, gdal.GetDataTypeByName(gdal_datatypes[datatype(output_array)]))\n"\
+ "out.SetGeoTransform( img.GetGeoTransform())\n"\
+ "out.SetProjection( img.GetProjectionRef())\n"\
+ "out.GetRasterBand(1).WriteArray(output_array)"

def getCopy(self):
newone = PymorphAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone

def getIcon(self):
return GeoAlgorithm.getIcon(self)

def defineCharacteristicsFromFile(self):
self.parameters.insert(0, ParameterRaster("input_filename", "Input image", False))
self.outputs.append(OutputRaster("output_filename", "Output image"))
self.script = self.LOAD_LAYER_SCRIPT + self.script + self.SAVE_LAYER_SCRIPT = AlgNames.getName(

def helpFile(self):
command = os.path.basename(self.descriptionFile)
command = command[:command.rfind(".")].replace("_", "")
filename = os.path.dirname(__file__) + "/html/morph/morph/mm" + command + ".html"
return filename

@@ -0,0 +1,43 @@
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.script.WrongScriptException import WrongScriptException
from sextante.core.SextanteLog import SextanteLog
from sextante.gdal.GdalUtils import GdalUtils
from sextante.pymorph.PymorphAlgorithm import PymorphAlgorithm

class PymorphAlgorithmProvider(AlgorithmProvider):

def __init__(self):

def scriptsFolder(self):
return os.path.dirname(__file__) + "/scripts"

def getDescription(self):
return "Pymorph (Morphological image processing tools)"

def getName(self):
return "pymorph"

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

def createAlgsList(self):
self.preloadedAlgs = []
folder = self.scriptsFolder()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("py"):
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
alg = PymorphAlgorithm(fullpath) = "Algorithms"
except WrongScriptException,e:

def getSupportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
@@ -0,0 +1,8 @@
import mmorph
import text
from mmorph import *
from text import *
from pymorph_version import __version__

__doc__ = mmorph.__doc__
__all__ = mmorph.__all__ + ['text']
@@ -0,0 +1,66 @@
add4dilate : Addition for dilation
addm : Addition of two images, with saturation.
areaclose : Area closing
areaopen : Area opening
asf : Alternating Sequential Filtering
asfrec : Reconstructive Alternating Sequential Filtering
binary : Convert a gray-scale image into a binary image
cbisector : N-Conditional bisector.
cdilate : Dilate an image conditionally.
center : Center filter.
cerode : Erode an image conditionally.
closeholes : Close holes of binary and gray-scale images.
close : Morphological closing.
closerec : Closing by reconstruction.
closerecth : Close-by-Reconstruction Top-Hat.
closeth : Closing Top Hat.
cthick : Image transformation by conditional thickening.
cthin : Image transformation by conditional thinning.
cwatershed : Detection of watershed from markers.
datatype : Return the image datatype string
dilate : Dilate an image by a structuring element.
dist : Distance transform.
endpoints : Interval to detect end-points.
erode : Erode an image by a structuring element.
flood : Flooding filter- h,v,a-basin and dynamics (depth, area, volume)
gdist : Geodesic Distance Transform.
gradm : Morphological gradient.
hmax : Remove peaks with contrast less than h.
hmin : Remove basins with contrast less than h.
homothick : Interval for homotopic thickening.
homothin : Interval for homotopic thinning.
infcanon : Intersection of inf-generating operators.
infgen : Inf-generating.
infrec : Inf-reconstruction.
inpos : Minima imposition.
interot : Rotate an interval
intersec : Intersection of images.
isolines : Apply an iso-line color table to a gray-scale image.
label : Label a binary image.
labelflat : Label the flat zones of gray-scale images.
lastero : Last erosion.
neg : Negate an image.
open : Morphological opening.
openrec : Opening by reconstruction.
openrecth : Open-by-Reconstruction Top-Hat.
openth : Opening Top Hat.
opentransf : Open transform.
patspec : Pattern spectrum (also known as granulometric size density).
randomcolor : Apply a random color table to a gray-scale image.
regmax : Regional Maximum.
regmin : Regional Minimum (with generalized dynamics).
skelm : Morphological skeleton (Medial Axis Transform).
skelmrec : Morphological skeleton reconstruction (Inverse Medial Axis Transform).
skiz : Skeleton of Influence Zone - also know as Generalized Voronoi Diagram
subm : Subtraction of two images, with saturation.
supcanon : Union of sup-generating or hit-miss operators.
supgen : Sup-generating (hit-miss).
suprec : Sup-reconstruction.
symdiff : Symmetric difference between two images
text : Create a binary image of a text.
thick : Image transformation by thickening.
thin : Image transformation by thinning.
threshad : Threshold (adaptive)
toggle : Image contrast enhancement or classification by the toggle operator.
union : Union of images.
watershed : Watershed detection.

0 comments on commit 40f1ea5

Please sign in to comment.