void RegionSeg::RegionProcess(IplImage *src, IplImage *dst, int areaThreshold)
{
	this->m_width = src->width;
	this->m_height = src->height;
	this->m_widthStep = src->widthStep;
	if(m_labelMap == NULL){
		m_labelMapLen = m_width * m_height * sizeof(int);
		m_labelMap = (int*)malloc(m_labelMapLen);
	}

	if(m_labelMapLen != m_width * m_height * sizeof(int)){
		free(m_labelMap);
		m_labelMapLen = m_width * m_height * sizeof(int);
		m_labelMap = (int*)malloc(m_labelMapLen);
	}

	memset(m_labelMap, 0, m_labelMapLen);

	m_neighboorQueue.CheckInit(m_height * m_width * 8);

	uchar* base = (uchar*)src->imageData;
	for(int y = 0; y < m_height; y++){
		int lineOffset = y * m_widthStep;
		base[lineOffset] = 0;
		base[lineOffset + 1] = 0;
		base[lineOffset + m_width - 2] = 0;
		base[lineOffset + m_width - 1] = 0;
	}
	memset(base, 0, 2 * m_widthStep);
	memset(base + (m_height - 2) * m_widthStep, 0, 2 * m_widthStep);

	ConnectedComponentLabeling(src);
	RegionErase((uchar*)src->imageData, areaThreshold);
	for(int y = 0; y < m_height; y++){
		uchar* p = (uchar*)dst->imageData + y * dst->widthStep;
		for(int x = 0; x < m_width; x++){
			*(p + x) = (uchar)m_labelMap[y * m_width + x];
		}
	}
}
Esempio n. 2
0
void main()
{
	//ConnectedComponentLabeling("D:/CodeBlocks/CCL/try.pbm", "0");// output label map
	ConnectedComponentLabeling("E:/Blob labeling/small.pbm", "1");// output label map and contour map
}