-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source code and compile scripts
- Loading branch information
Andrea Tangherloni
authored
May 16, 2019
1 parent
68dadcb
commit a7fce63
Showing
66 changed files
with
7,509 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
#include "AggregatedGrayPair.h" | ||
|
||
AggregatedGrayPair::AggregatedGrayPair() { | ||
grayLevel = 0; | ||
frequency = 0; | ||
} | ||
|
||
AggregatedGrayPair::AggregatedGrayPair(grayLevelType i, frequencyType freq){ | ||
grayLevel = i; | ||
frequency = freq; | ||
} | ||
|
||
void AggregatedGrayPair::printPair() const { | ||
std::cout << "k: " << grayLevel; | ||
std::cout << "\freq: " << frequency; | ||
std::cout << std::endl; | ||
} | ||
|
||
/* Extracting the pairs */ | ||
grayLevelType AggregatedGrayPair::getAggregatedGrayLevel() const{ | ||
return grayLevel; | ||
} | ||
|
||
frequencyType AggregatedGrayPair::getFrequency() const { | ||
return frequency; | ||
} | ||
|
||
bool AggregatedGrayPair::compareTo(AggregatedGrayPair other) const{ | ||
return (grayLevel == other.getAggregatedGrayLevel()); | ||
} | ||
|
||
void AggregatedGrayPair::increaseFrequency(frequencyType amount){ | ||
frequency += amount; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifndef FEATUREEXTRACTOR_AGGREGATEDGRAYPAIR_H | ||
#define FEATUREEXTRACTOR_AGGREGATEDGRAYPAIR_H | ||
|
||
// Custom types for code reusability | ||
// Unsigned shorts halve the memory footprint of the application | ||
typedef unsigned short grayLevelType; | ||
typedef unsigned short frequencyType; | ||
|
||
/** | ||
* This class represents two possible types of elements: | ||
* - Elements obtained by summing or subtracting two gray levels of a pixel pair | ||
* - Elements representing the frequency of one of the two gray levels of the | ||
* pixel pairs (reference gray level or neighbor gray level) | ||
*/ | ||
|
||
class AggregatedGrayPair { | ||
public: | ||
/** | ||
* Constructor for initializing pre-allocated work areas | ||
*/ | ||
AggregatedGrayPair(); | ||
/** | ||
* Constructor for effective gray-tone pairs | ||
* @param level: gray level of the object | ||
* @param frequency: frequency of the object | ||
*/ | ||
AggregatedGrayPair(grayLevelType level, frequencyType frequency); | ||
|
||
/** | ||
* Shows textual representation with level and frequency | ||
*/ | ||
void printPair() const; | ||
/** | ||
* Getter | ||
* @return the gray level of the object | ||
*/ | ||
grayLevelType getAggregatedGrayLevel() const; | ||
/** | ||
* Getter | ||
* @return the frequency of the object | ||
*/ | ||
frequencyType getFrequency() const; | ||
/** | ||
* Setter | ||
* @param amount that will increment the frequency | ||
*/ | ||
void increaseFrequency(frequencyType amount); | ||
|
||
/** | ||
* Method to compare two AggregatedGrayPair objects according to the | ||
* equality of gray levels | ||
* @param other: object of the same type | ||
* @return true if the two objects have the same gray level | ||
*/ | ||
bool compareTo(AggregatedGrayPair other) const; | ||
|
||
// Overloaded C++ operators inherited from implementation that uses STL | ||
bool operator==(const AggregatedGrayPair& other) const{ | ||
return (grayLevel == other.getAggregatedGrayLevel()); | ||
} | ||
|
||
bool operator<(const AggregatedGrayPair& other) const{ | ||
return (grayLevel < other.getAggregatedGrayLevel()); | ||
} | ||
|
||
AggregatedGrayPair& operator++(){ | ||
this->frequency += 1; | ||
return *this; | ||
} | ||
private: | ||
grayLevelType grayLevel; | ||
frequencyType frequency; | ||
|
||
}; | ||
|
||
|
||
#endif //FEATUREEXTRACTOR_AGGREGATEDGRAYPAIR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
#include "Direction.h" | ||
|
||
Direction::Direction(int directionNumber) { | ||
switch (directionNumber){ | ||
case 1:{ | ||
char templabel[20] = "Direction 0°"; | ||
memcpy(this->label, templabel, 20); | ||
this->label[20] = 0; | ||
shiftRows = 0; | ||
shiftColumns = 1; | ||
break; | ||
} | ||
case 2:{ | ||
char templabel[20] = "Direction 45°"; | ||
memcpy(this->label, templabel, 20); | ||
this->label[20] = 0; | ||
shiftRows = -1; | ||
shiftColumns = 1; | ||
break; | ||
} | ||
case 3:{ | ||
char templabel[20] = "Direction 90°"; | ||
memcpy(this->label, templabel, 20); | ||
this->label[20] = 0; | ||
shiftRows = -1; | ||
shiftColumns = 0; | ||
break; | ||
} | ||
case 4:{ | ||
char templabel[20] = "Direction 135°"; | ||
memcpy(this->label, templabel, 20); | ||
this->label[20] = 0; | ||
shiftRows = -1; | ||
shiftColumns = -1; | ||
break; | ||
} | ||
default: | ||
fprintf(stderr, "Unsupported direction"); | ||
exit(-1); | ||
} | ||
} | ||
|
||
void Direction::printDirectionLabel(const int direction){ | ||
switch(direction){ | ||
case 1: | ||
printf(" * Direction 0° *\n"); | ||
case 2: | ||
printf(" * Direction 45° *\n"); | ||
case 3: | ||
printf(" * Direction 90° *\n"); | ||
case 4: | ||
printf(" * Direction 135° *\n"); | ||
default: | ||
fprintf(stderr, "Fatal Error! Unsupported direction"); | ||
exit(-1); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
#ifndef FEATUREEXTRACTOR_DIRECTION_H | ||
#define FEATUREEXTRACTOR_DIRECTION_H | ||
|
||
/** | ||
* This class represents one of the supported directions; | ||
* it embeds values for locating reference-neighbor pixel pairs. | ||
* Supported directions with their associated eoncoding: | ||
* 0°[1], 45°[2], 90° [3], 135° [4] | ||
*/ | ||
|
||
class Direction { | ||
public: | ||
/** | ||
* Constructs an object of the Direction class | ||
* @param directionNumber: the encoding associated with the direction: | ||
* 0°[1], 45°[2], 90° [3], 135° [4] | ||
*/ | ||
Direction(int directionNumber); | ||
|
||
/** | ||
* Shows info about the direction | ||
* @param direction: the encoding associated with the direction: | ||
* 0°[1], 45°[2], 90° [3], 135° [4] | ||
*/ | ||
static void printDirectionLabel(const int direction); | ||
char label[20]; | ||
/** | ||
* Shift on the y axis to denote the neighbor pixel | ||
*/ | ||
int shiftRows; | ||
/** | ||
* Shift on the x axis to denote the neighbor pixel | ||
*/ | ||
int shiftColumns; | ||
}; | ||
|
||
|
||
#endif //FEATUREEXTRACTOR_DIRECTION_H |
Oops, something went wrong.