Skip to content

Commit

Permalink
Merge branch 'main' into image_quality_v5
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseMckinzie committed May 22, 2024
2 parents 98b3ef1 + c472f21 commit 0322a6b
Show file tree
Hide file tree
Showing 55 changed files with 1,757 additions and 1,322 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ set(SOURCE
src/nyx/features/saturation.cpp
src/nyx/features/sharpness.cpp
src/nyx/features/specfunc.cpp
src/nyx/features/texture_feature.cpp
src/nyx/features/zernike.cpp
src/nyx/features/zernike_nontriv.cpp
src/nyx/helpers/timing.cpp
src/nyx/cli_fpimage_options.cpp
src/nyx/cli_gabor_options.cpp
src/nyx/cli_glcm_options.cpp
src/nyx/cli_nested_roi_options.cpp
src/nyx/common_stats.cpp
src/nyx/dirs_and_files.cpp
Expand Down
52 changes: 52 additions & 0 deletions src/nyx/cli_glcm_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "cli_glcm_options.h"
#include "features/glcm.h"

using namespace Nyxus;

bool GLCMoptions::parse_input()
{
if (!rawAngles.empty())
{
//==== Parse rotations
if (!rawAngles.empty())
{
std::string ermsg;
if (!Nyxus::parse_delimited_string_list_to_ints(rawAngles, glcmAngles, ermsg))
{
std::cerr << "Error parsing list of integers " << rawAngles << ": " << ermsg << "\n";
return false;
}

// The angle list parsed well, let's tell it to GLCMFeature
GLCMFeature::angles = glcmAngles;
}
}

if (!rawOffs.empty())
{
// string -> real
int x;
bool ok = Nyxus::parse_as_int (rawOffs, x);
if (!ok || x <= 0)
{
ermsg = "Error in " + rawOffs + ": expecting a positive integer value";
return false;
}

// set feature class parameter
GLCMFeature::offset = x;
}

return true;
}

bool GLCMoptions::empty()
{
return rawAngles.empty() && rawOffs.empty();
}

std::string GLCMoptions::get_last_er_msg()
{
return ermsg;
}

25 changes: 25 additions & 0 deletions src/nyx/cli_glcm_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <string>
#include <vector>

class GLCMoptions
{
public:
// Parses 'raw*', set 'defined_' and 'ermsg'
bool parse_input();

std::string get_last_er_msg();

bool empty();

// intentionally public to be accessed by Environment
std::string rawOffs = "", // matches GLCMOFFSET
rawAngles = ""; // matches GLCMANGLES

std::vector<int> glcmAngles = { 0, 45, 90, 135 };

private:
bool defined_ = false;
std::string ermsg = "";
};
53 changes: 34 additions & 19 deletions src/nyx/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Environment::show_cmdline_help()
<< "\t\t" << OPT << PXLDIST << "=<number of pixels as neighbor features radius> \n"
<< "\t\t\tDefault: 5 \n"
<< "\t\t" << OPT << COARSEGRAYDEPTH << "=<custom number of grayscale levels> \n"
<< "\t\t\tDefault: 256 \n"
<< "\t\t\tDefault: 64 \n"
<< "\t\t" << OPT << GLCMANGLES << "=<one or more comma separated rotation angles from set {0, 45, 90, and 135}> \n"
<< "\t\t\tDefault: 0,45,90,135 \n"
<< "\t\t" << OPT << VERBOSITY << "=<levels of verbosity 0 (silence), 1 (minimum output), 2 (1 + timing), 3 (2 + roi metrics + more timing), 4 (3 + diagnostic information)> \n"
Expand Down Expand Up @@ -265,6 +265,9 @@ bool Environment::find_string_argument(std::vector<std::string>::iterator& i, co
std::string a = arg;
if (actualArgName == a)
{
if (arg_value.length())
std::cerr << "Warning: " << a << " already has value \'" << arg_value << "\'\n";

arg_value = *++i;
recognizedArgs.push_back({ a, arg_value });
return true;
Expand All @@ -276,6 +279,9 @@ bool Environment::find_string_argument(std::vector<std::string>::iterator& i, co
auto pos = actualArgName.find(a);
if (pos != std::string::npos)
{
if (arg_value.length())
std::cerr << "Warning: " << a << " already has value \'" << arg_value << "\'\n";

arg_value = actualArgName.substr(a.length());
recognizedArgs.push_back({ a, arg_value });
return true;
Expand Down Expand Up @@ -358,7 +364,8 @@ bool Environment::parse_cmdline(int argc, char** argv)
find_string_argument(i, LOADERTHREADS, loader_threads) ||
find_string_argument(i, PXLSCANTHREADS, pixel_scan_threads) ||
find_string_argument(i, REDUCETHREADS, reduce_threads) ||
find_string_argument(i, GLCMANGLES, rawGlcmAngles) ||
find_string_argument(i, GLCMANGLES, glcmOptions.rawAngles) ||
find_string_argument(i, GLCMOFFSET, glcmOptions.rawOffs) ||
find_string_argument(i, PXLDIST, pixel_distance) ||
find_string_argument(i, COARSEGRAYDEPTH, raw_coarse_grayscale_depth) ||
find_string_argument(i, VERBOSITY, rawVerbosity) ||
Expand Down Expand Up @@ -584,9 +591,9 @@ bool Environment::parse_cmdline(int argc, char** argv)
if (!raw_coarse_grayscale_depth.empty())
{
// string -> integer
if (sscanf(raw_coarse_grayscale_depth.c_str(), "%d", &coarse_grayscale_depth) != 1 || coarse_grayscale_depth <= 0)
if (sscanf(raw_coarse_grayscale_depth.c_str(), "%d", &coarse_grayscale_depth) != 1)
{
std::cerr << "Error: " << COARSEGRAYDEPTH << "=" << raw_coarse_grayscale_depth << ": expecting a positive integer constant\n";
std::cerr << "Error: " << COARSEGRAYDEPTH << "=" << raw_coarse_grayscale_depth << ": expecting an integer constant\n";
return false;
}
}
Expand All @@ -601,20 +608,6 @@ bool Environment::parse_cmdline(int argc, char** argv)
}
}

//==== Parse rotations
if (!rawGlcmAngles.empty())
{
std::string ermsg;
if (!Nyxus::parse_delimited_string_list_to_ints(rawGlcmAngles, glcmAngles, ermsg))
{
std::cerr << "Error parsing list of integers " << rawGlcmAngles << ": " << ermsg << "\n";
return false;
}

// The angle list parsed well, let's tell it to GLCMFeature
GLCMFeature::angles = glcmAngles;
}

//==== Parse the RAM limit (in megabytes)
if (!rawRamLimit.empty())
{
Expand Down Expand Up @@ -678,6 +671,17 @@ bool Environment::parse_cmdline(int argc, char** argv)
}
}

//==== Parse GLCM options
if (!glcmOptions.empty())
{
std::string ermsg;
if (!this->parse_glcm_options_raw_inputs(ermsg))
{
std::cerr << ermsg << "\n";
return false;
}
}

//==== Parse floating point image options
if (!fpimageOptions.empty())
{
Expand Down Expand Up @@ -852,7 +856,7 @@ int Environment::get_floating_point_precision()
return floating_point_precision;
}

unsigned int Environment::get_coarse_gray_depth()
int Environment::get_coarse_gray_depth()
{
return coarse_grayscale_depth;
}
Expand Down Expand Up @@ -912,6 +916,17 @@ bool Environment::parse_gabor_options_raw_inputs(std::string& error_message)
return true;
}

bool Environment::parse_glcm_options_raw_inputs (std::string& error_message)
{

if (!glcmOptions.parse_input())
{
error_message = glcmOptions.get_last_er_msg();
return false;
}
return true;
}

bool Environment::parse_fpimage_options_raw_inputs(std::string& error_message)
{
if (!fpimageOptions.parse_input())
Expand Down
23 changes: 13 additions & 10 deletions src/nyx/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#include "environment_basic.h"
#include "cli_fpimage_options.h"
#include "cli_gabor_options.h"
#include "cli_glcm_options.h"
#include "cli_nested_roi_options.h"
#include "roi_blacklist.h"
#include "save_option.h"



#ifdef USE_GPU
#include <cuda_runtime.h>
#endif
Expand All @@ -31,7 +30,6 @@
#define LOADERTHREADS "--loaderThreads" // Environment :: n_loader_threads
#define PXLSCANTHREADS "--pxlscanThreads" // Environment :: n_pixel_scan_threads
#define REDUCETHREADS "--reduceThreads" // Environment :: n_reduce_threads
#define GLCMANGLES "--glcmAngles" // Environment :: rotAngles
#define VERBOSITY "--verbose" // Environment :: verbosity_level -- Example: --verbosity=3
#define ONLINESTATSTHRESH "--onlineStatsThresh" // Environment :: onlineStatsThreshold -- Example: --onlineStatsThresh=150
#define XYRESOLUTION "--pixelsPerCentimeter" // pixels per centimeter
Expand All @@ -54,14 +52,18 @@
#endif

// Gabor feature CLI arguments
#define GABOR_FREQS "--gaborfreqs" // Example: "2,4,8,72"
#define GABOR_FREQS "--gaborfreqs" // Example: "2,4,8,72". Frequencies should atch thetas: --gaborfreqs=1,2,3,4,5 --gabortheta=30,30,45,90,90
#define GABOR_GAMMA "--gaborgamma" // Example: "0.1"
#define GABOR_SIG2LAM "--gaborsig2lam" // Example: "0.8"
#define GABOR_KERSIZE "--gaborkersize" // Example: "20"
#define GABOR_F0 "--gaborf0" // Example: "0.1"
#define GABOR_THETA "--gabortheta" // Example: "60"
#define GABOR_THETA "--gabortheta" // Example: "60,45,90"
#define GABOR_THRESHOLD "--gaborthold" // Example: "0.025"

// GLCM feature
#define GLCMANGLES "--glcmAngles" // Environment :: rotAngles
#define GLCMOFFSET "--glcmOff" // Environment :: raw_glcm_

// Nested ROI functionality
#define NESTEDROI_CHNL_SIGNATURE "--hsig" // Channel signature Example: "_c" in "p0_y1_r1_c1.ome.tiff"
#define NESTEDROI_PARENT_CHNL "--hpar" // Channel number that should be used as a provider of parent segments. Example: --hpar=1
Expand Down Expand Up @@ -129,9 +131,6 @@ class Environment: public BasicEnvironment
std::string pixel_distance = "";
int n_pixel_distance = 5;

std::string rawGlcmAngles = "";
std::vector<int> glcmAngles = {0, 45, 90, 135};

std::string rawVerbosity = ""; // 'verbosity_level' is inherited from BasicEnvironment

std::string rawOnlineStatsThresh = "";
Expand Down Expand Up @@ -174,7 +173,7 @@ class Environment: public BasicEnvironment

int get_floating_point_precision();

unsigned int get_coarse_gray_depth();
int get_coarse_gray_depth();
void set_coarse_gray_depth(unsigned int new_depth);

// implementation of SKIPROI
Expand All @@ -187,6 +186,10 @@ class Environment: public BasicEnvironment
bool parse_gabor_options_raw_inputs (std::string& error_message);
GaborOptions gaborOptions;

// implementation of GLCM feature options
bool parse_glcm_options_raw_inputs (std::string& error_message);
GLCMoptions glcmOptions;

// implementation of nested ROI options
bool parse_nested_options_raw_inputs (std::string& error_message);
NestedRoiOptions nestedOptions;
Expand Down Expand Up @@ -221,7 +224,7 @@ class Environment: public BasicEnvironment

int floating_point_precision = 10;

unsigned int coarse_grayscale_depth = 256;
int coarse_grayscale_depth = 64;
std::string raw_coarse_grayscale_depth = "";

// data members implementing RAMLIMIT
Expand Down
4 changes: 4 additions & 0 deletions src/nyx/feature_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class FeatureManager

void apply_user_selection();

// Initializes feature classes
// (allocates lookup tables, precalculates filter banks, etc.)
bool init_feature_classes();

// After compiling, returns the number of user-requested features
int get_num_requested_features();

Expand Down
4 changes: 4 additions & 0 deletions src/nyx/feature_mgr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ FeatureManager::FeatureManager()
register_feature (new PowerSpectrumFeature());
register_feature (new SaturationFeature());
register_feature (new SharpnessFeature());
}bool FeatureManager::init_feature_classes()
{
return GaborFeature::init_class();
}

8 changes: 8 additions & 0 deletions src/nyx/features/aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class AABB
inline StatsInt get_ymin() const { return ymin; }
inline StatsInt get_ymax() const { return ymax; }

void init_from_widthheight (StatsInt w, StatsInt h)
{
xmin = 0;
xmax = w;
ymin = 0;
ymax = h;
}

static std::tuple<StatsInt, StatsInt, StatsInt, StatsInt> from_pixelcloud (const std::vector<Pixel2>& P)
{
AABB bb;
Expand Down
4 changes: 2 additions & 2 deletions src/nyx/features/contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void ContourFeature::buildRegularContour(LR& r)
);

//==== Remove padding and save the contour image as a vector of non-blank pixels
AABB & bb = r.aabb; // r.aux_image_matrix.original_aabb;
AABB & bb = r.aabb;
int base_x = bb.get_xmin(),
base_y = bb.get_ymin();
r.contour.clear();
Expand Down Expand Up @@ -610,7 +610,7 @@ void ContourFeature::buildRegularContour_nontriv(LR& r)
}

//==== Remove padding and save the contour image as a vector of contour-onlu pixels
AABB& bb = r.aabb; // r.aux_image_matrix.original_aabb;
AABB& bb = r.aabb;
int base_x = bb.get_xmin(),
base_y = bb.get_ymin();
r.contour.clear();
Expand Down
Loading

0 comments on commit 0322a6b

Please sign in to comment.