阅读背景:

提取图像里面的红色灯笼(二)

来源:互联网 

首先对图像进行简单的阈值处理:

/**************************************************************

函数功能:对图像hsi空间红色灯笼的提取

输入参数:源图像src;目标图像des;图像参数width,height,nChannels;

输出参数:目标图像

**************************************************************/

void hsi_seg(unsigned char* des, const unsigned char* src, int width, int height, int nChannels)

{

printf("%d,%d,%d,",nChannels,width,height);

unsigned char* ocl = new unsigned char[width * height * nChannels];

unsigned char* hsi = new unsigned char[width * height * nChannels];

rgb_hsi(hsi,src, width, height, nChannels);//hsi分量提取

for(int y = 0; y < height; y++)

{

for(int x = 0; x < width; x++)

{

int img_H= hsi[y * width * nChannels + x * nChannels ] ;

int img_S= hsi[y * width * nChannels + x * nChannels + 1] ;

int img_I= hsi[y * width * nChannels + x * nChannels + 2] ;

if((img_H<104)&&(img_H>102)&&(img_I>40)&&(img_S>60))

{

//printf("%d, ",img_S);

for(int n=0;n<nChannels;n++)

des[y * width * nChannels + x * nChannels + n] = src[y * width * nChannels + x * nChannels + n] ;

}

else

for(int n=0;n<nChannels;n++)

des[y * width * nChannels + x * nChannels + n] =255;

}

}

ImageDilation(ocl, des, width, height, nChannels,3);//进行3*3的模板膨胀
/************************



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: