Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <mexutils.h>
00016
00017 #include <vl/generic.h>
00018
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <math.h>
00022
00023 #undef T
00024 #undef SFX
00025 #define T vl_int32
00026 #define SFX i
00027 #include "samplinthist.tc"
00028
00029 #undef T
00030 #undef SFX
00031 #define T vl_uint32
00032 #define SFX ui
00033 #include "samplinthist.tc"
00034
00035 #undef T
00036 #undef SFX
00037 #define T double
00038 #define SFX d
00039 #include "samplinthist.tc"
00040
00041 #undef T
00042 #undef SFX
00043 #define T float
00044 #define SFX f
00045 #include "samplinthist.tc"
00046
00047 void
00048 mexFunction(int nout, mxArray *out[],
00049 int nin, const mxArray *in[])
00050 {
00051 mwSize dims [3] ;
00052 int numDims ;
00053 mwSize const * dimsPt = 0 ;
00054
00055 void* histPt = 0 ;
00056 void const* intHistPt = 0 ;
00057 vl_uint32 const* boxesPt = 0 ;
00058 size_t numLabels = 0 ;
00059 mxClassID histClass = mxUINT32_CLASS ;
00060 size_t numBoxes = 0 ;
00061 int width, height ;
00062
00063 enum {IN_INTHIST = 0, IN_BOXES, IN_END} ;
00064 enum {OUT_HIST = 0} ;
00065
00066
00067
00068
00069 if (nin != 2) {
00070 vlmxError(vlmxErrInvalidArgument,
00071 "Two arguments required.") ;
00072 } else if (nout > 1) {
00073 vlmxError(vlmxErrInvalidArgument,
00074 "Too many output arguments.");
00075 }
00076
00077 histClass = mxGetClassID(in[IN_INTHIST]) ;
00078 if (histClass != mxDOUBLE_CLASS &&
00079 histClass != mxUINT32_CLASS) {
00080 vlmxError(vlmxErrInvalidArgument,
00081 "INTHIST must be of either class DOUBLE or UINT32.") ;
00082 }
00083
00084 numDims = mxGetNumberOfDimensions(in[IN_INTHIST]) ;
00085 if (numDims > 3) {
00086 vlmxError(vlmxErrInvalidArgument,
00087 "INTHIST must be a MxNxK array.") ;
00088 }
00089 intHistPt = mxGetData(in[IN_INTHIST]) ;
00090
00091 dimsPt = mxGetDimensions(in[IN_INTHIST]) ;
00092 height = dimsPt [0] ;
00093 width = dimsPt [1] ;
00094 numLabels = (numDims >= 3) ? dimsPt [2] : 1 ;
00095
00096 numBoxes = mxGetNumberOfElements(in[IN_BOXES]) ;
00097 if (numBoxes % 4 != 0) {
00098 vlmxError(vlmxErrInvalidArgument,
00099 "The number of elements of BOXES must be a multiple of four.") ;
00100 }
00101 numBoxes /= 4 ;
00102
00103 if (mxGetClassID(in[IN_BOXES]) != mxUINT32_CLASS) {
00104 vlmxError(vlmxErrInvalidArgument,
00105 "BOXES must be of class UINT32.") ;
00106 }
00107 boxesPt = (vl_uint32*) mxGetData(in[IN_BOXES]) ;
00108
00109
00110 dims [0] = numLabels ;
00111 dims [1] = numBoxes ;
00112 out [OUT_HIST] = mxCreateNumericArray(2, dims, histClass, mxREAL) ;
00113 histPt = mxGetData(out[OUT_HIST]) ;
00114
00115
00116
00117
00118
00119 #define PROCESS(SAMPLE, T) \
00120 SAMPLE (histPt, \
00121 intHistPt, height, width, numLabels, \
00122 boxesPt, numBoxes) ;
00123
00124 switch (histClass) {
00125 case mxDOUBLE_CLASS: { PROCESS(sample_d, double) } ; break ;
00126 case mxUINT32_CLASS: { PROCESS(sample_ui, vl_uint32) } ; break ;
00127 default:
00128 abort() ;
00129 }
00130 }