利用OpenCV实现图像纹理特征提取
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv

·
这个程序是简单地图像纹理特征提取,参考代码如下所示:
IplImage * cvSampleImageTextureExtraction(IplImage* img,IplImage* dst){
uchar* data=(uchar*)img->imageData;
int step=img->widthStep;
//IplImage* dst=cvCreateImage(cvSize(img->width,img->height),img->depth,1);
dst->widthStep=img->widthStep;
CvScalar s;
int tmp[8]={0};
int sum=0;int k=0;
for(int i=1;i<img->height-1;i++)
for(int j=1;j<img->width-1;j++){
if(data[(i-1)*step+j-1]>data[i*step+j])
tmp[0]=1;
else
tmp[0]=0;
if(data[i*step+(j-1)]>data[i*step+j])
tmp[1]=1;
else
tmp[1]=0;
if(data[(i+1)*step+(j-1)]>data[i*step+j])
tmp[2]=1;
else
tmp[2]=0;
if (data[(i+1)*step+j]>data[i*step+j])
tmp[3]=1;
else
tmp[3]=0;
if (data[(i+1)*step+(j+1)]>data[i*step+j])
tmp[4]=1;
else tmp[4]=0;
if(data[i*step+(j+1)]>data[i*step+j])
tmp[5]=1;
else
tmp[5]=0;
if(data[(i-1)*step+(j+1)]>data[i*step+j])
tmp[6]=1;
else
tmp[6]=0;
if(data[(i-1)*step+j]>data[i*step+j])
tmp[7]=1;
else
tmp[7]=0;
for(k=0;k<=7;k++)
sum+=abs(tmp[k]-tmp[k+1]);
sum=sum+abs(tmp[7]-tmp[0]);
if (sum<=2)
s.val[0]=(tmp[0]*128+tmp[1]*64+tmp[2]*32+tmp[3]*16+tmp[4]*8+tmp[5]*4+tmp[6]*2+tmp[7]);
else
s.val[0]=59;
cvSet2D(dst,i,j,s);
}
return dst;
}
测试结果输出如下所示:
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
输出图像纹理效果图如下图所示:
关于Image Engineering & Computer Vision的更多讨论与交流,敬请关注本博客和新浪微博songzi_tea.
推荐内容
阅读全文
AI总结




OpenCV: 开源计算机视觉库
最近提交(Master分支:7 个月前 )
cd5a6364
HAL: aligned behavior of normDiff 32s kernels in hal_rvv in 4.x 1 天前
a7749c38 - 1 天前
更多推荐
相关推荐
查看更多
opencv

OpenCV:开放源代码计算机视觉库
opencv

opencv

R bindings for OpenCV
所有评论(0)