📄 signdist.mex.c
字号:
/* file: signdist.c** description: MEX weighted signdist function.** author: Andrea Vedaldi**//* AUTORIGHTSCopyright (C) 2006 Regents of the University of CaliforniaAll rights reservedWritten by Andrea Vedaldi (UCLA VisionLab).Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of California, Berkeley nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANYEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ANDON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#include<mexutils.c>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<assert.h>#define ABS(x) (((x)>0)?(x):(-(x)))/* driver */voidmexFunction(int nout, mxArray *out[], int nin, const mxArray *in[]){ typedef char unsigned sig_t ; typedef int unsigned out_t ; typedef int acc_t ; /* mxClassID data_class = mxINT8_CLASS ;*/ enum {IN_S1,IN_S2} ; enum {OUT_D=0} ; int M,N1,N2 ; sig_t* s1_pt ; sig_t* s2_pt ; /** ----------------------------------------------------------------- ** Check the arguments ** -------------------------------------------------------------- */ if (nin != 2) { mexErrMsgTxt("Two arguments required.") ; } else if (nout > 1) { mexErrMsgTxt("Too many output arguments."); } if(mxGetClassID(in[IN_S1]) != mxUINT8_CLASS || mxGetClassID(in[IN_S2]) != mxUINT8_CLASS ) { mexErrMsgTxt("S1 and S2 must be of class uint8") ; } M = mxGetM(in[IN_S1]) ; /* n of components */ N1 = mxGetN(in[IN_S1]) ; /* n of elements */ N2 = mxGetN(in[IN_S2]) ; /* n of elements */ if( M != mxGetM(in[IN_S2]) ) { mexErrMsgTxt("S1 and S2 must have the same number of columns") ; } s1_pt = mxGetData(in[IN_S1]) ; s2_pt = mxGetData(in[IN_S2]) ; { int dims [2] ; dims[0] = N1 ; dims[1] = N2 ; out[OUT_D] = mxCreateNumericArray(2,dims,mxUINT32_CLASS, mxREAL) ; } /** ----------------------------------------------------------------- ** Go ** -------------------------------------------------------------- */ { int j1,j2,i ; out_t* pt = mxGetData(out[OUT_D]) ; for(j2 = 0 ; j2 < N2 ; ++j2) { for(j1 = 0 ; j1 < N1 ; ++j1) { if(j1>=j2) { acc_t acc = 0 ; for(i = 0 ; i < M ; ++i) { acc_t x1 = s1_pt[j1*M+i] ; acc_t x2 = s2_pt[j2*M+i] ; acc_t delta = x2-x1 ; acc += ABS(delta) ; } *pt = acc; } pt++ ; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -