Created
July 25, 2016 08:43
-
-
Save pinetum/f07fdaeb6448a8f2c964cd3892ef66ea to your computer and use it in GitHub Desktop.
getLabelContourMask
This file contains hidden or 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
void CSID::getLabelContourMask(cv::Mat &mask, bool _thick_line) | |
{ | |
// default width | |
int line_width = 2; | |
if ( !_thick_line ) line_width = 1; | |
int width = m_matData.cols; | |
int height = m_matData.rows; | |
mask.create(height, width, CV_8UC1 ); | |
mask.setTo(0); | |
const int dx8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; | |
const int dy8[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; | |
int sz = width*height; | |
std::vector<bool> istaken(sz, false); | |
int mainindex = 0; | |
for( int j = 0; j < height; j++ ) | |
{ | |
for( int k = 0; k < width; k++ ) | |
{ | |
int np = 0; | |
for( int i = 0; i < 8; i++ ) | |
{ | |
int x = k + dx8[i]; | |
int y = j + dy8[i]; | |
if( (x >= 0 && x < width) && (y >= 0 && y < height) ) | |
{ | |
int index = y*width + x; | |
if( false == istaken[index] ) | |
{ | |
if( m_labelData.at<int>(j,k) != m_labelData.at<int>(y,x) ) np++; | |
} | |
} | |
} | |
if( np > line_width ) | |
{ | |
mask.at<char>(j,k) = -1; | |
istaken[mainindex] = true; | |
} | |
mainindex++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment