Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POL5645 Combinable 3D features #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 46 additions & 145 deletions src/nyx/env_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "features/3d_ngldm.h"
#include "features/3d_ngtdm.h"
#include "features/3d_gldzm.h"
#include "features/3d_glrlm.h"
#include "features/3d_glszm.h"
#include "features/roi_radius.h"
#include "helpers/helpers.h"
Expand Down Expand Up @@ -131,8 +132,8 @@ bool Environment::spellcheck_raw_featurelist(const std::string& comma_separated_

if (dim() == 3)
{
// Is feature found among 2D features?
Fgroup3D afg;
// Is feature found among 3D features?
int afg; // signed Fgroup3D
bool gnameExists = theFeatureSet.find_3D_GroupByString (s_uppr, afg);

// Intercept an error: 3D feature group exists but requested in the non-3D mode
Expand All @@ -150,7 +151,7 @@ bool Environment::spellcheck_raw_featurelist(const std::string& comma_separated_
continue;
}

Feature3D af;
int af; // signed Feature3D
bool fnameExists = theFeatureSet.find_3D_FeatureByString (s_uppr, af);

// 3D feature group requested on a non-3D mode ?
Expand Down Expand Up @@ -353,11 +354,19 @@ bool Environment::expand_2D_featuregroup (const std::string & s)
//
bool Environment::expand_3D_featuregroup (const std::string& s)
{
// mutually exclusive groups:
if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_ALL))
int fgcode;
if (!Nyxus::theFeatureSet.find_3D_GroupByString(s, fgcode))
return false; // 's' is a feature name
bool enable = true;
if (fgcode < 0)
{
theFeatureSet.enableAll(false);
fgcode = -fgcode;
enable = false;
}

// mutually exclusive groups:
if ((Fgroup3D)fgcode == Fgroup3D::FG3_ALL)
{
auto F =
{
Feature3D::COV,
Expand Down Expand Up @@ -439,172 +448,61 @@ bool Environment::expand_3D_featuregroup (const std::string& s)
#endif
};

theFeatureSet.enableFeatures (F);
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset);
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset);
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset);
theFeatureSet.enableFeatures (F, enable);
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable);
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable);

return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLCM)
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset);
theFeatureSet.enableFeatures (D3_GLCM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_GLDM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDM)
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset);
theFeatureSet.enableFeatures (D3_GLDM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGLDM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGLDM)
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset);
theFeatureSet.enableFeatures (D3_NGLDM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode (Fgroup3D::FG3_NGTDM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_NGTDM)
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset);
theFeatureSet.enableFeatures (D3_NGTDM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLCM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLDZM)
{
theFeatureSet.enableAll (false);

auto F =
{
Nyxus::Feature3D::GLCM_ACOR,
Nyxus::Feature3D::GLCM_ASM,
Nyxus::Feature3D::GLCM_CLUPROM,
Nyxus::Feature3D::GLCM_CLUSHADE,
Nyxus::Feature3D::GLCM_CLUTEND,
Nyxus::Feature3D::GLCM_CONTRAST,
Nyxus::Feature3D::GLCM_CORRELATION,
Nyxus::Feature3D::GLCM_DIFAVE,
Nyxus::Feature3D::GLCM_DIFENTRO,
Nyxus::Feature3D::GLCM_DIFVAR,
Nyxus::Feature3D::GLCM_DIS,
Nyxus::Feature3D::GLCM_ENERGY,
Nyxus::Feature3D::GLCM_ENTROPY,
Nyxus::Feature3D::GLCM_HOM1,
Nyxus::Feature3D::GLCM_HOM2,
Nyxus::Feature3D::GLCM_ID,
Nyxus::Feature3D::GLCM_IDN,
Nyxus::Feature3D::GLCM_IDM,
Nyxus::Feature3D::GLCM_IDMN,
Nyxus::Feature3D::GLCM_INFOMEAS1,
Nyxus::Feature3D::GLCM_INFOMEAS2,
Nyxus::Feature3D::GLCM_IV,
Nyxus::Feature3D::GLCM_JAVE,
Nyxus::Feature3D::GLCM_JE,
Nyxus::Feature3D::GLCM_JMAX,
Nyxus::Feature3D::GLCM_JVAR,
Nyxus::Feature3D::GLCM_SUMAVERAGE,
Nyxus::Feature3D::GLCM_SUMENTROPY,
Nyxus::Feature3D::GLCM_SUMVARIANCE,
Nyxus::Feature3D::GLCM_VARIANCE,
Nyxus::Feature3D::GLCM_ASM_AVE,
Nyxus::Feature3D::GLCM_ACOR_AVE,
Nyxus::Feature3D::GLCM_CLUPROM_AVE,
Nyxus::Feature3D::GLCM_CLUSHADE_AVE,
Nyxus::Feature3D::GLCM_CLUTEND_AVE,
Nyxus::Feature3D::GLCM_CONTRAST_AVE,
Nyxus::Feature3D::GLCM_CORRELATION_AVE,
Nyxus::Feature3D::GLCM_DIFAVE_AVE,
Nyxus::Feature3D::GLCM_DIFENTRO_AVE,
Nyxus::Feature3D::GLCM_DIFVAR_AVE,
Nyxus::Feature3D::GLCM_DIS_AVE,
Nyxus::Feature3D::GLCM_ENERGY_AVE,
Nyxus::Feature3D::GLCM_ENTROPY_AVE,
Nyxus::Feature3D::GLCM_HOM1_AVE,
Nyxus::Feature3D::GLCM_ID_AVE,
Nyxus::Feature3D::GLCM_IDN_AVE,
Nyxus::Feature3D::GLCM_IDM_AVE,
Nyxus::Feature3D::GLCM_IDMN_AVE,
Nyxus::Feature3D::GLCM_IV_AVE,
Nyxus::Feature3D::GLCM_JAVE_AVE,
Nyxus::Feature3D::GLCM_JE_AVE,
Nyxus::Feature3D::GLCM_INFOMEAS1_AVE,
Nyxus::Feature3D::GLCM_INFOMEAS2_AVE,
Nyxus::Feature3D::GLCM_VARIANCE_AVE,
Nyxus::Feature3D::GLCM_JMAX_AVE,
Nyxus::Feature3D::GLCM_JVAR_AVE,
Nyxus::Feature3D::GLCM_SUMAVERAGE_AVE,
Nyxus::Feature3D::GLCM_SUMENTROPY_AVE,
Nyxus::Feature3D::GLCM_SUMVARIANCE_AVE
};

theFeatureSet.enableFeatures(F);
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLDZM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLSZM)
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_GLDZM_feature::featureset);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLSZM))
{
theFeatureSet.enableAll (false);
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset);
theFeatureSet.enableFeatures (D3_GLSZM_feature::featureset, enable);
return true;
}

if (s == Nyxus::theFeatureSet.findGroupNameByCode(Fgroup3D::FG3_GLRLM))
if ((Fgroup3D)fgcode == Fgroup3D::FG3_GLRLM)
{
theFeatureSet.enableAll(false);

auto F =
{
Nyxus::Feature3D::GLRLM_SRE,
Nyxus::Feature3D::GLRLM_LRE,
Nyxus::Feature3D::GLRLM_GLN,
Nyxus::Feature3D::GLRLM_GLNN,
Nyxus::Feature3D::GLRLM_RLN,
Nyxus::Feature3D::GLRLM_RLNN,
Nyxus::Feature3D::GLRLM_RP,
Nyxus::Feature3D::GLRLM_GLV,
Nyxus::Feature3D::GLRLM_RV,
Nyxus::Feature3D::GLRLM_RE,
Nyxus::Feature3D::GLRLM_LGLRE,
Nyxus::Feature3D::GLRLM_HGLRE,
Nyxus::Feature3D::GLRLM_SRLGLE,
Nyxus::Feature3D::GLRLM_SRHGLE,
Nyxus::Feature3D::GLRLM_LRLGLE,
Nyxus::Feature3D::GLRLM_LRHGLE,

Nyxus::Feature3D::GLRLM_SRE_AVE,
Nyxus::Feature3D::GLRLM_LRE_AVE,
Nyxus::Feature3D::GLRLM_GLN_AVE,
Nyxus::Feature3D::GLRLM_GLNN_AVE,
Nyxus::Feature3D::GLRLM_RLN_AVE,
Nyxus::Feature3D::GLRLM_RLNN_AVE,
Nyxus::Feature3D::GLRLM_RP_AVE,
Nyxus::Feature3D::GLRLM_GLV_AVE,
Nyxus::Feature3D::GLRLM_RV_AVE,
Nyxus::Feature3D::GLRLM_RE_AVE,
Nyxus::Feature3D::GLRLM_LGLRE_AVE,
Nyxus::Feature3D::GLRLM_HGLRE_AVE,
Nyxus::Feature3D::GLRLM_SRLGLE_AVE,
Nyxus::Feature3D::GLRLM_SRHGLE_AVE,
Nyxus::Feature3D::GLRLM_LRLGLE_AVE,
Nyxus::Feature3D::GLRLM_LRHGLE_AVE
};

theFeatureSet.enableFeatures(F);
theFeatureSet.enableFeatures (D3_GLRLM_feature::featureset, enable);
return true;
}

// unrecognized feature group
return false;
}

Expand Down Expand Up @@ -643,6 +541,8 @@ void Environment::expand_featuregroups()
continue;
}

// try to interpret 's' as a group name

if (dim() == 2)
{
if (expand_2D_featuregroup (s))
Expand All @@ -656,24 +556,25 @@ void Environment::expand_featuregroups()
}

// 's' is an individual feature name, not feature group name. Process it now

if (dim() == 2)
{
int fcode; // signed Feature2D
if (!theFeatureSet.find_2D_FeatureByString (s, fcode))
if (!Nyxus::theFeatureSet.find_2D_FeatureByString (s, fcode))
throw std::invalid_argument("Error: '" + s + "' is not a valid 2D feature name \n");

theFeatureSet.enableFeature (fcode);
Nyxus::theFeatureSet.enableFeature (fcode);

continue;
}

if (dim() == 3)
{
Feature3D a;
if (!theFeatureSet.find_3D_FeatureByString(s, a))
int a; // signed Feature3D
if (!Nyxus::theFeatureSet.find_3D_FeatureByString(s, a))
throw std::invalid_argument("Error: '" + s + "' is not a valid 3D feature name \n");

theFeatureSet.enableFeature (int(a));
Nyxus::theFeatureSet.enableFeature (int(a));
continue;
}
}
Expand Down
32 changes: 24 additions & 8 deletions src/nyx/featureset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,6 @@ bool FeatureSet::find_2D_GroupByString (
enable = name[0] == '+' ? 1 : -1;
}


// search
auto itr = Nyxus::UserFacing2dFeaturegroupNames.find (s);

Expand All @@ -957,39 +956,56 @@ bool FeatureSet::find_2D_GroupByString (
return true;
}

bool FeatureSet::find_3D_FeatureByString (const std::string & name, Feature3D & f)
bool FeatureSet::find_3D_FeatureByString (const std::string & name, int & f)
{
int enable = 1;

// strip possible set operation '+' or '-'
std::string s = name;

if (name[0] == '-' || name[0] == '+')
s = name.substr(1);
// digest optional unary operator (sign)
if (std::ispunct(name[0]))
if (name[0] == '-' || name[0] == '+')
{
s = name.substr(1);
enable = name[0] == '+' ? 1 : -1;
}
else
return false; // invalid unary operator

// search
auto it_f = Nyxus::UserFacing_3D_featureNames.find (s);
auto it_f = Nyxus::UserFacing_3D_featureNames.find(s);

if (it_f == Nyxus::UserFacing_3D_featureNames.end())
return false;

f = it_f->second;
f = enable * (int)it_f->second;

return true;
}

bool FeatureSet::find_3D_GroupByString (const std::string & name, Fgroup3D & grpCode)
bool FeatureSet::find_3D_GroupByString (const std::string & name, int & grpCode)
{
int enable = 1;

// strip possible set operation '+' or '-'
std::string s = name;

// digest optional unary operator (sign)
if (name[0] == '-' || name[0] == '+')
{
s = name.substr(1);
enable = name[0] == '+' ? 1 : -1;
}

// search
auto itr = Nyxus::UserFacing3dFeaturegroupNames.find (s);

if (itr == Nyxus::UserFacing3dFeaturegroupNames.end())
return false;

grpCode = itr->second;
grpCode = enable * (int)itr->second;

return true;
}

Expand Down
14 changes: 7 additions & 7 deletions src/nyx/featureset.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ namespace Nyxus
enum class Fgroup2D
{
FG2_ALL = 0,
FG2_WHOLESLIDE,
FG2_WHOLESLIDE, // FG2_WHOLESLIDE is FG2_ALL for whole slides
FG2_INTENSITY,
FG2_MORPHOLOGY,
FG2_BASIC_MORPHOLOGY,
Expand Down Expand Up @@ -925,10 +925,10 @@ class FeatureSet
for (auto f : F)
m_enabledFeatures[(int)f] = enable;
}
void enableFeatures(const std::initializer_list<Nyxus::Feature3D>& desiredFeatures)
void enableFeatures(const std::initializer_list<Nyxus::Feature3D>& F, bool enable = true)
{
for (auto f : desiredFeatures)
m_enabledFeatures[(int)f] = true;
for (auto f : F)
m_enabledFeatures[(int)f] = enable;
}
void enableFeatures(const std::initializer_list<Nyxus::FeatureIMQ>& desiredFeatures) {
for (auto f : desiredFeatures)
Expand Down Expand Up @@ -1039,10 +1039,10 @@ class FeatureSet
cnt++;
return cnt;
}
bool find_2D_FeatureByString (const std::string& name, int& f); // 'f' is signed Feature2D
bool find_2D_FeatureByString (const std::string & name, int & f); // 'f' is signed Feature2D
bool find_2D_GroupByString (const std::string& group_name, int & group_code); // 'group_code' is signed Nyxus::Fgroup2D
bool find_3D_FeatureByString (const std::string & feature_name, Nyxus::Feature3D & feature_code);
bool find_3D_GroupByString (const std::string & group_name, Nyxus::Fgroup3D & group_code);
bool find_3D_FeatureByString (const std::string & feature_name, int & feature_code);
bool find_3D_GroupByString (const std::string & group_name, int & group_code);
bool find_IMQ_FeatureByString (const std::string & feature_name, Nyxus::FeatureIMQ & feature_code);
bool find_IMQ_GroupByString (const std::string & group_name, Nyxus::FgroupIMQ & group_code);

Expand Down
Loading
Loading