Skip to content

Commit

Permalink
Merge pull request #149 from eEcoLiDAR/feature_148_intensity
Browse files Browse the repository at this point in the history
Feature 148 intensity
  • Loading branch information
meiertgrootes authored Dec 3, 2019
2 parents cf84dc1 + f49c3d9 commit 3555d82
Show file tree
Hide file tree
Showing 46 changed files with 607 additions and 674 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.3.2 - 2019-11-
## Added
- Features:
'max_intensity', 'min_intensity', 'range_intensity', 'mean_intensity', 'std_intensity', 'coeff_var_intensity'

## Changed
- Features renamed','median_norm_z'
'max_norm_z', 'min_norm_z', 'range_norm_z', 'mean_norm_z', 'std_norm_z', 'coeff_var_norm_z', 'density_absolute_mean_norm_z', 'entropy_norm_z','kurto_norm_z', 'skew_norm_z','var_z', 'perc_1_norm_z', 'perc_100_norm_z'
'min_normalized_height', 'max_normalized_height', 'range_normalized_height', 'mean_normalized_height','std_normalized_height', 'coeff_var_normalized_height', 'density_absolute_mean_normalized_height','entropy_normalized_height','kurto_normalized_height','median_normalized_height', 'skew_normalized_height','var_normalized_height', 'perc_1_normalized_height', 'perc_100_normalized_height'


## 0.3.1 - 2019-09-25
## Added
- Percentiles 1-100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def _is_ground(i, point_cloud):
return point_cloud[point]['raw_classification']["data"][i] in GROUND_TAGS


class DensityAbsoluteMeanZFeatureExtractor(FeatureExtractor):
class DensityAbsoluteMeanFeatureExtractor(FeatureExtractor):
"""Feature extractor for the point density."""
DATA_KEY = 'z'
def __init__(self, data_key='z'):
self.data_key = data_key

@classmethod
def requires(cls):
Expand All @@ -33,8 +34,7 @@ def requires(cls):
"""
return []

@classmethod
def provides(cls):
def provides(self):
"""
Get a list of names of the feature values.
Expand All @@ -44,7 +44,7 @@ def provides(cls):
:return: List of feature names
"""
return ['density_absolute_mean_z']
return ['density_absolute_mean_' + self.data_key]

def extract(self, point_cloud, neighborhood, target_point_cloud, target_index, volume_description):
"""
Expand Down Expand Up @@ -76,12 +76,12 @@ def _get_ground_indices(point_cloud, ground_tags):

def _get_density_absolute_mean(self, non_ground_indices, source_point_cloud):
n_non_ground = len(non_ground_indices)
z_non_ground = source_point_cloud[point][self.DATA_KEY]["data"][non_ground_indices]
data_non_ground = source_point_cloud[point][self.data_key]["data"][non_ground_indices]
if n_non_ground == 0:
density_absolute_mean = 0.
else:
density_absolute_mean = float(
len(z_non_ground[z_non_ground > np.mean(z_non_ground)])) / n_non_ground * 100.
len(data_non_ground[data_non_ground > np.mean(data_non_ground)])) / n_non_ground * 100.
return density_absolute_mean

def get_params(self):
Expand Down

This file was deleted.

47 changes: 47 additions & 0 deletions laserchicken/feature_extractor/entropy_feature_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Shannan entropy calculation. For more info see https://rdrr.io/cran/lidR/man/entropy.html"""

import numpy as np
from laserchicken import keys
from laserchicken.feature_extractor.base_feature_extractor import FeatureExtractor


class EntropyFeatureExtractor(FeatureExtractor):
layer_thickness = 0.5
min_val = None
max_val = None

def __init__(self, data_key='z'):
self.data_key = data_key

@classmethod
def requires(cls):
return []

def provides(self):
return ['entropy_' + self.data_key]

def get_params(self):
p = [self.layer_thickness]
if self.min_val is not None:
p.append(self.min_val)
if self.max_val is not None:
p.append(self.max_val)
return p

def extract(self, source_pc, neighborhood, target_pc, target_index, volume_description):
if len(neighborhood) == 0:
return 0
source_data = source_pc[keys.point][self.data_key]["data"][neighborhood]
data_min = np.min(source_data) if self.min_val is None else self.min_val
data_max = np.max(source_data) if self.max_val is None else self.max_val
if data_min == data_max:
return 0
n_bins = int(np.ceil((data_max - data_min) / self.layer_thickness))
data = np.histogram(source_data, bins=n_bins, range=(data_min, data_max), density=True)[0]
entropy_func = np.vectorize(_x_log_2x)
norm = np.sum(data)
return -(entropy_func(data / norm)).sum()


def _x_log_2x(x):
return 0 if x == 0 else x * np.log2(x)
12 changes: 0 additions & 12 deletions laserchicken/feature_extractor/entropy_norm_z_feature_extractor.py

This file was deleted.

48 changes: 0 additions & 48 deletions laserchicken/feature_extractor/entropy_z_feature_extractor.py

This file was deleted.

67 changes: 29 additions & 38 deletions laserchicken/feature_extractor/feature_map.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
from laserchicken import keys
from laserchicken.feature_extractor.band_ratio_feature_extractor import BandRatioFeatureExtractor
from .density_absolute_mean_norm_z_feature_extractor import DensityAbsoluteMeanNormZFeatureExtractor
from .density_absolute_mean_z_feature_extractor import DensityAbsoluteMeanZFeatureExtractor
from .density_absolute_mean_feature_extractor import DensityAbsoluteMeanFeatureExtractor
from .density_feature_extractor import PointDensityFeatureExtractor
from .echo_ratio_feature_extractor import EchoRatioFeatureExtractor
from .eigenvals_feature_extractor import EigenValueVectorizeFeatureExtractor
from .entropy_norm_z_feature_extractor import EntropyNormZFeatureExtractor
from .entropy_z_feature_extractor import EntropyZFeatureExtractor
from .kurtosis_norm_z_feature_extractor import KurtosisNormZFeatureExtractor
from .kurtosis_z_feature_extractor import KurtosisZFeatureExtractor
from .mean_std_coeff_norm_z_feature_extractor import MeanStdCoeffNormZFeatureExtractor
from .mean_std_coeff_z_feature_extractor import MeanStdCoeffZFeatureExtractor
from .median_norm_z_feature_extractor import MedianNormZFeatureExtractor
from .median_z_feature_extractor import MedianZFeatureExtractor
from .percentile_norm_z_feature_extractor import PercentileNormZFeatureExtractor
from .percentile_z_feature_extractor import PercentileZFeatureExtractor
from .entropy_feature_extractor import EntropyFeatureExtractor
from .kurtosis_feature_extractor import KurtosisFeatureExtractor
from .mean_std_coeff_feature_extractor import MeanStdCoeffFeatureExtractor
from .median_feature_extractor import MedianFeatureExtractor
from .percentile_feature_extractor import PercentileFeatureExtractor
from .pulse_penetration_feature_extractor import PulsePenetrationFeatureExtractor
from .range_norm_z_feature_extractor import RangeNormZFeatureExtractor
from .range_z_feature_extractor import RangeZFeatureExtractor
from .range_feature_extractor import RangeFeatureExtractor
from .sigma_z_feature_extractor import SigmaZFeatureExtractor
from .skew_norm_z_feature_extractor import SkewNormZFeatureExtractor
from .skew_z_feature_extractor import SkewZFeatureExtractor
from .var_norm_z_feature_extractor import VarianceNormZFeatureExtractor
from .var_z_feature_extractor import VarianceZFeatureExtractor
from .skew_feature_extractor import SkewFeatureExtractor
from .var_feature_extractor import VarianceFeatureExtractor


def create_default_feature_map():
Expand All @@ -45,29 +36,29 @@ def _get_default_extractors():
return [PointDensityFeatureExtractor(),
EchoRatioFeatureExtractor(),
EigenValueVectorizeFeatureExtractor(),
EntropyZFeatureExtractor(),
PercentileZFeatureExtractor(),
EntropyFeatureExtractor(),
EntropyFeatureExtractor(data_key=keys.normalized_height),
PulsePenetrationFeatureExtractor(),
SigmaZFeatureExtractor(),
MedianZFeatureExtractor(),
RangeZFeatureExtractor(),
VarianceZFeatureExtractor(),
MeanStdCoeffZFeatureExtractor(),
SkewZFeatureExtractor(),
KurtosisZFeatureExtractor(),
SkewNormZFeatureExtractor(),
MeanStdCoeffNormZFeatureExtractor(),
VarianceNormZFeatureExtractor(),
RangeNormZFeatureExtractor(),
KurtosisNormZFeatureExtractor(),
EntropyNormZFeatureExtractor(),
MedianNormZFeatureExtractor(),
PercentileNormZFeatureExtractor(),
DensityAbsoluteMeanZFeatureExtractor(),
DensityAbsoluteMeanNormZFeatureExtractor(),
MedianFeatureExtractor(),
MedianFeatureExtractor(data_key=keys.normalized_height),
VarianceFeatureExtractor(),
VarianceFeatureExtractor(data_key=keys.normalized_height),
MeanStdCoeffFeatureExtractor(),
MeanStdCoeffFeatureExtractor(data_key=keys.normalized_height),
MeanStdCoeffFeatureExtractor(data_key=keys.intensity),
SkewFeatureExtractor(),
SkewFeatureExtractor(data_key=keys.normalized_height),
KurtosisFeatureExtractor(),
KurtosisFeatureExtractor(data_key=keys.normalized_height),
RangeFeatureExtractor(),
RangeFeatureExtractor(data_key=keys.normalized_height),
RangeFeatureExtractor(data_key=keys.intensity),
DensityAbsoluteMeanFeatureExtractor(),
DensityAbsoluteMeanFeatureExtractor(data_key=keys.normalized_height),
BandRatioFeatureExtractor(None, 1, data_key=keys.normalized_height),
BandRatioFeatureExtractor(1, 2, data_key=keys.normalized_height),
BandRatioFeatureExtractor(2, 3, data_key=keys.normalized_height),
BandRatioFeatureExtractor(3, None, data_key=keys.normalized_height)] \
+ [PercentileZFeatureExtractor(p) for p in range(1, 101)] \
+ [PercentileNormZFeatureExtractor(p) for p in range(1, 101)]
+ [PercentileFeatureExtractor(percentile=p) for p in range(1, 101)] \
+ [PercentileFeatureExtractor(percentile=p, data_key=keys.normalized_height) for p in range(1, 101)]
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import numpy as np
import scipy.stats.stats as stat

from laserchicken.feature_extractor.base_feature_extractor import FeatureExtractor
from laserchicken.keys import point


class KurtosisZFeatureExtractor(FeatureExtractor):
"""Calculates the variation on the z axis."""
DATA_KEY = 'z'

@classmethod
def requires(cls):
return []

@classmethod
def provides(cls):
return ['kurto_z']

def extract(self, sourcepc, neighborhood, targetpc, targetindex, volume_description):
if neighborhood:
z = sourcepc[point][self.DATA_KEY]['data'][neighborhood]
kurtosis_z = stat.kurtosis(z)
else:
kurtosis_z = np.NaN
return kurtosis_z
import numpy as np
import scipy.stats.stats as stat

from laserchicken.feature_extractor.base_feature_extractor import FeatureExtractor
from laserchicken.keys import point


class KurtosisFeatureExtractor(FeatureExtractor):
"""Calculates the variation on the z axis."""
def __init__(self, data_key='z'):
self.data_key = data_key

@classmethod
def requires(cls):
return []

def provides(self):
return ['kurto_' + self.data_key]

def extract(self, sourcepc, neighborhood, targetpc, targetindex, volume_description):
if neighborhood:
z = sourcepc[point][self.data_key]['data'][neighborhood]
kurtosis_z = stat.kurtosis(z)
else:
kurtosis_z = np.NaN
return kurtosis_z

This file was deleted.

Loading

0 comments on commit 3555d82

Please sign in to comment.