www.pudn.com > edgehist.rar > edgehist.cpp
/* * IMAGE EXTRACTION LIBRARY * * DISCOVIR - Distributed Content-based Visual Information Retrieval System on Peer-to-Peer(P2P) Network * http://www.cse.cuhk.edu.hk/~miplab/discovir * * Copyright (C) 2002 Multimedia Information Processing Laboratory * http://www.cse.cuhk.edu.hk/~miplab * The Chinese University of Hong Kong * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * */ #include#include #include #define FRONT 255 #define BKGRND 0 ///////////////////////////////////////////////////////////////////////////// unsigned char *ImageConvertedFromFloatArray(int n, float *array) { unsigned char *img=new unsigned char[n]; for(int i=0; i =0)&&(i2 =0)&&(j2 0) result[j*m_X+i]=(unsigned char)(temp/summask); else result[j*m_X+i]=pImageBuf[j*m_X+i]; } return result; } ///////////////////////////////////////////////////////////////////////////// float *ImageGradient(unsigned char *pImageBuf, int m_X, int m_Y, int masksize, float *mask, int number) { float *gradient= new float[m_X*m_Y]; int i, j, i1, j1, i2, j2, width; width=masksize/2; float temp; for(j=0;j m_Y-width-1)||(i m_Y-width-1)) gradient[j*m_X+i]=0; else { temp=0; for(j1=-width; j1<= width; j1++) for(i1=-width; i1<= width; i1++) { i2=i+i1; j2=j+j1; temp+=float(pImageBuf[j2*m_X+i2])*mask[(j1+width)*masksize+(i1+width)]; } gradient[j*m_X+i]=temp/number; } } return gradient; } ///////////////////////////////////////////////////////////////////////////// int MyMathFunctionAtan(float p, float q) { float theta, pi; int degree; pi=float(3.1415926); theta=float(atan(double(q)/double(p))); if(p<0) theta+=pi; if(theta<0) theta+=2*pi; if(theta>2*pi) theta-=2*pi; degree=int(360*theta/(2*pi)); return degree; } ///////////////////////////////////////////////////////////////////////////// float *ImageEdgeDirectionHistogram(unsigned char *edge, float *p, float *q, int n, float thr, int BIN_NUM) { int i, degree, bin_width, nEdge; float magnitude; bin_width=360/BIN_NUM; float *histogram=new float[BIN_NUM]; for(i=0; i thr) { edge[i]=FRONT; degree=MyMathFunctionAtan(p[i], q[i]); histogram[degree/bin_width]+=1; nEdge+=1; } else edge[i]=BKGRND; } if(nEdge!=0) { for(i=0; i