Skip to content

Commit

Permalink
Merge pull request lagadic#1311 from rolalaro/feat_cht_masks
Browse files Browse the repository at this point in the history
Use of boolean mask
  • Loading branch information
fspindle authored Jan 24, 2024
2 parents d016c3e + ed5d19a commit 1b34914
Show file tree
Hide file tree
Showing 15 changed files with 2,003 additions and 948 deletions.
6 changes: 5 additions & 1 deletion cmake/VISPDetectCXXStandard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ set(VISP_CXX_STANDARD_17 201703L)

if(DEFINED USE_CXX_STANDARD)

if(USE_CXX_STANDARD STREQUAL "11")
if(USE_CXX_STANDARD STREQUAL "98")
set(CMAKE_CXX_STANDARD 98)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_98})
set(CXX98_CXX_FLAGS "-std=c++98" CACHE STRING "C++ compiler flags for C++98 support")
elseif(USE_CXX_STANDARD STREQUAL "11")
set(CMAKE_CXX_STANDARD 11)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_11})
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
Expand Down
4 changes: 3 additions & 1 deletion cmake/VISPFindUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ include(CheckCXXSourceCompiles)
macro(check_math_expr _expr _header _var)
unset(${_var} CACHE)
# Since check_cxx_source_compiles() doesn't consider CXX_STANDARD we add the corresponding flag manually
if((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_11) AND CXX11_CXX_FLAGS)
if((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_98) AND CXX98_CXX_FLAGS)
set(CMAKE_REQUIRED_FLAGS ${CXX98_CXX_FLAGS})
elseif((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_11) AND CXX11_CXX_FLAGS)
set(CMAKE_REQUIRED_FLAGS ${CXX11_CXX_FLAGS})
elseif((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_14) AND CXX14_CXX_FLAGS)
set(CMAKE_REQUIRED_FLAGS ${CXX14_CXX_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
#cmakedefine VISP_HAVE_NLOHMANN_JSON

// Define c++ standard values also available in __cplusplus when gcc is used
#define VISP_CXX_STANDARD_98 ${VISP_CXX_STANDARD_98} # Keep for compat with previous releases
#define VISP_CXX_STANDARD_98 ${VISP_CXX_STANDARD_98}
#define VISP_CXX_STANDARD_11 ${VISP_CXX_STANDARD_11}
#define VISP_CXX_STANDARD_14 ${VISP_CXX_STANDARD_14}
#define VISP_CXX_STANDARD_17 ${VISP_CXX_STANDARD_17}
Expand Down
16 changes: 16 additions & 0 deletions modules/core/include/visp3/core/vpCannyEdgeDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class VISP_EXPORT vpCannyEdgeDetection
std::map<std::pair<unsigned int, unsigned int>, EdgeType> m_edgePointsCandidates; /*!< Map that contains the strong edge points, i.e. the points for which we know for sure they are edge points,
and the weak edge points, i.e. the points for which we still must determine if they are actual edge points.*/
vpImage<unsigned char> m_edgeMap; /*!< Final edge map that results from the whole Canny algorithm.*/
const vpImage<bool> *mp_mask; /*!< Mask that permits to consider only the pixels for which the mask is true.*/

/** @name Constructors and initialization */
//@{
Expand Down Expand Up @@ -366,6 +367,21 @@ class VISP_EXPORT vpCannyEdgeDetection
m_gradientFilterKernelSize = apertureSize;
initGradientFilters();
}

/**
* \brief Set a mask to ignore pixels for which the mask is false.
*
* \warning The mask must be reset manually by the user (either for another mask
* or set to \b nullptr ) before computing the edge-map of another image.
*
* @param p_mask If different of \b nullptr , a mask of booleans where \b true
* indicates that a pixel must be considered and \b false that the pixel should
* be ignored.
*/
inline void setMask(const vpImage<bool> *p_mask)
{
mp_mask = p_mask;
}
//@}
};
#endif
66 changes: 43 additions & 23 deletions modules/core/include/visp3/core/vpHistogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class VISP_EXPORT vpHistogram
vpHistogram();
vpHistogram(const vpHistogram &h);
explicit vpHistogram(const vpImage<unsigned char> &I);
explicit vpHistogram(const vpImage<unsigned char> &I, const vpImage<bool> *p_mask);
virtual ~vpHistogram();

vpHistogram &operator=(const vpHistogram &h);
Expand All @@ -136,12 +137,12 @@ class VISP_EXPORT vpHistogram
*/
inline unsigned operator[](const unsigned char level) const
{
if (level < size) {
return histogram[level];
if (level < m_size) {
return m_histogram[level];
}

std::stringstream ss;
ss << "Level is > to size (" << size << ") !";
ss << "Level is > to size (" << m_size << ") !";
throw vpException(vpException::dimensionError, ss.str().c_str());
};
/*!
Expand All @@ -166,12 +167,12 @@ class VISP_EXPORT vpHistogram
*/
inline unsigned operator()(const unsigned char level) const
{
if (level < size) {
return histogram[level];
if (level < m_size) {
return m_histogram[level];
}

std::stringstream ss;
ss << "Level is > to size (" << size << ") !";
ss << "Level is > to size (" << m_size << ") !";
throw vpException(vpException::dimensionError, ss.str().c_str());
};
/*!
Expand All @@ -196,12 +197,12 @@ class VISP_EXPORT vpHistogram
*/
inline unsigned get(const unsigned char level) const
{
if (level < size) {
return histogram[level];
if (level < m_size) {
return m_histogram[level];
}

std::stringstream ss;
ss << "Level is > to size (" << size << ") !";
ss << "Level is > to size (" << m_size << ") !";
throw vpException(vpException::dimensionError, ss.str().c_str());
};

Expand All @@ -224,15 +225,31 @@ class VISP_EXPORT vpHistogram
*/
inline void set(const unsigned char level, unsigned int value)
{
if (level < size) {
histogram[level] = value;
} else {
if (level < m_size) {
m_histogram[level] = value;
}
else {
std::stringstream ss;
ss << "Level is > to size (" << size << ") !";
ss << "Level is > to size (" << m_size << ") !";
throw vpException(vpException::dimensionError, ss.str().c_str());
}
};

/**
* \brief Set a mask to ignore pixels for which the mask is false.
*
* \warning The mask must be reset manually by the user (either for another mask
* or set to \b nullptr ) before computing the histogram of another image.
*
* @param p_mask If different of \b nullptr , a mask of booleans where \b true
* indicates that a pixel must be considered and \b false that the pixel should
* be ignored.
*/
inline void setMask(const vpImage<bool> *p_mask)
{
mp_mask = p_mask;
}

void calculate(const vpImage<unsigned char> &I, unsigned int nbins = 256, unsigned int nbThreads = 1);
void equalize(const vpImage<unsigned char> &I, vpImage<unsigned char> &Iout);

Expand Down Expand Up @@ -260,7 +277,7 @@ class VISP_EXPORT vpHistogram
\sa getValues()
*/
inline unsigned getSize() const { return size; };
inline unsigned getSize() const { return m_size; };

/*!
Expand All @@ -283,19 +300,22 @@ class VISP_EXPORT vpHistogram
\sa getSize()
*/
inline unsigned *getValues() { return histogram; };
inline unsigned *getValues() { return m_histogram; };

/**
* \brief Get the total number of pixels in the input image.
*
* \return unsigned int Cumulated number of pixels in the input image.
*/
inline unsigned int getTotal() { return m_total; };

private:
void init(unsigned size = 256);

unsigned int *histogram;
unsigned size; // Histogram size (max allowed 256)
unsigned int *m_histogram; /*!< The storage for the histogram.*/
unsigned m_size; /*!< Histogram size (max allowed 256).*/
const vpImage<bool> *mp_mask; /*!< Mask that permits to consider only the pixels for which the mask is true.*/
unsigned int m_total; /*!< Cumulated number of pixels in the input image. */
};

#endif

/*
* Local variables:
* c-basic-offset: 2
* End:
*/
9 changes: 9 additions & 0 deletions modules/core/include/visp3/core/vpImageCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class VISP_EXPORT vpImageCircle
*/
float computeArcLengthInRoI(const vpRect &roi, const float &roundingTolerance = 0.001f) const;

/**
* \brief Count the number of pixels of the circle whose value in the mask is true.
*
* \param mask A mask where true indicates that a pixel must be taken into account and false
* that it must be ignored.
* \return unsigned int The number of pixels in the mask.
*/
unsigned int computePixelsInMask(const vpImage<bool> &mask) const;

/*!
* Get the center of the image (2D) circle
* \return The center of the image (2D) circle.
Expand Down
Loading

0 comments on commit 1b34914

Please sign in to comment.