Skip to content
Permalink
Browse files
implemented a few more pymorph algorithms
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@184 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com committed May 17, 2012
1 parent 40f1ea5 commit 16b3417f70d4207d7715e9dc316d136a0b9431a8
@@ -9,20 +9,24 @@ class PymorphAlgorithm(ScriptAlgorithm):

LOAD_LAYER_SCRIPT = "from sextante.gdal.GdalUtils import GdalUtils\n" \
+"from sextante.pymorph.mmorph import datatype\n" \
+ "import numpy\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"
+ "input_array = img.ReadAsArray()\n" \
+ "if isinstance(input_array[0][0], (numpy.float32, numpy.float64)):\n" \
+ "\tinput_array = input_array.astype(numpy.int32)\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 = drv.Create(output_filename, img.RasterXSize, img.RasterYSize, 1, gdal.GetDataTypeByName('UInt16'))\n"\
+ "out.SetGeoTransform( img.GetGeoTransform())\n"\
+ "out.SetProjection( img.GetProjectionRef())\n"\
+ "out.GetRasterBand(1).WriteArray(output_array)"
#gdal_datatypes[datatype(output_array)]

def getCopy(self):
newone = PymorphAlgorithm(self.descriptionFile)
Empty file.
@@ -0,0 +1,2 @@
from sextante.pymorph.mmorph import erode
output_array=erode(input_array)
Empty file.
@@ -0,0 +1,2 @@
from sextante.pymorph.mmorph import gdist
output_array=gdist(input_array)
@@ -0,0 +1,2 @@
from sextante.pymorph.mmorph import gradm
output_array=gradm(input_array)
@@ -0,0 +1,3 @@
##Contrast_threshold=number 1
from sextante.pymorph.mmorph import hmax
output_array=hmax(input_array, Contrast_threshold)
@@ -0,0 +1,3 @@
##Contrast_threshold=number 1
from sextante.pymorph.mmorph import hmin
output_array=hmin(input_array, Contrast_threshold)
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
@@ -0,0 +1,5 @@
##Binary_marker_image=raster
from sextante.pymorph.mmorph import inpos, binary
img2 = gdal.Open(Binary_marker_image)
input_array2 = img2.ReadAsArray()
output_array=inpos(binary(input_array2), input_array)
Empty file.
Empty file.
@@ -0,0 +1,3 @@
##Number_of_isolines=number 10
from sextante.pymorph.mmorph import isolines
output_array=isolines(input_array, Number_of_isolines)

0 comments on commit 16b3417

Please sign in to comment.