Add normalization choice

This commit is contained in:
Florent Guiotte 2018-09-12 21:57:21 +02:00
parent bbec5fbb95
commit 7ec65323d9

View File

@ -15,7 +15,7 @@ import numpy as np
from .CreaTIFF import read, write from .CreaTIFF import read, write
class Triskele: class Triskele:
def __init__(self, raster, dtype=np.uint8, cache_dir='/tmp', verbose=True): def __init__(self, raster, dtype=np.uint8, normalize_to_dtype=True, cache_dir='/tmp', verbose=True):
self.verbose = verbose self.verbose = verbose
self.triskele_bin = Path(os.path.dirname(os.path.realpath(__file__))\ self.triskele_bin = Path(os.path.dirname(os.path.realpath(__file__))\
@ -35,7 +35,7 @@ class Triskele:
self.sdfile = self.cache_dir.joinpath('sdfile.txt') self.sdfile = self.cache_dir.joinpath('sdfile.txt')
self.moifile = self.cache_dir.joinpath('moifile.txt') self.moifile = self.cache_dir.joinpath('moifile.txt')
self._write_infile(raster, dtype) self._write_infile(raster, dtype, normalize_to_dtype)
def filter(self, tree='max-tree', area=None, standard_deviation=None, moment_of_inertia=None, feature='weight'): def filter(self, tree='max-tree', area=None, standard_deviation=None, moment_of_inertia=None, feature='weight'):
self._setup(tree, area, standard_deviation, moment_of_inertia, feature) self._setup(tree, area, standard_deviation, moment_of_inertia, feature)
@ -45,11 +45,12 @@ class Triskele:
def _read_outfile(self): def _read_outfile(self):
return read(self.outfile) return read(self.outfile)
def _write_infile(self, rasters, dtype): def _write_infile(self, rasters, dtype, normalize_to_dtype):
## Expand if rasters is 2D ## Expand if rasters is 2D
if len(rasters.shape) < 3: if len(rasters.shape) < 3:
rasters = np.expand_dims(rasters, 2) rasters = np.expand_dims(rasters, 2)
if normalize_to_dtype:
## Scale to new dtype ## Scale to new dtype
rep = np.iinfo(dtype) rep = np.iinfo(dtype)