Пример #1
0
static void
icxLogicSM( const void* srcarr, CxScalar* scalar, void* dstarr,
            const void* maskarr, CxArithmUniMaskFunc2D func )
{
    CX_FUNCNAME( "icxLogicSM" );
    
    __BEGIN__;

    double buf[12];
    int coi1 = 0, coi2 = 0;
    CxMat  srcstub, *src = (CxMat*)srcarr;
    CxMat  dststub, *dst = (CxMat*)dstarr;
    CxMat  maskstub, *mask = (CxMat*)maskarr;
    int pix_size, type;
    int dst_step, mask_step;
    CxSize size;

    if( !CX_IS_MAT(src))
        CX_CALL( src = cxGetMat( src, &srcstub, &coi1 ));

    if( !CX_IS_MAT(dst))
        CX_CALL( dst = cxGetMat( dst, &dststub ));

    if( coi1 != 0 || coi2 != 0 )
        CX_ERROR( CX_BadCOI, "" );

    CX_CALL( mask = cxGetMat( mask, &maskstub ));

    if( !CX_IS_MASK_ARR(mask) )
        CX_ERROR_FROM_CODE( CX_StsBadMask );

    if( !CX_ARE_SIZES_EQ( mask, dst ) )
        CX_ERROR_FROM_CODE( CX_StsUnmatchedSizes );

    if( src->data.ptr != dst->data.ptr )
    {
        CX_CALL( cxCopy( src, dst, mask ));
    }

    size = cxGetMatSize( dst );
    dst_step = dst->step;
    mask_step = mask->step;

    if( CX_IS_MAT_CONT( mask->type & dst->type ))
    {
        size.width *= size.height;
        dst_step = mask_step = CX_STUB_STEP;
        size.height = 1;
    }

    type = CX_MAT_TYPE( src->type );
    pix_size = icxPixSize[type];
    
    CX_CALL( cxScalarToRawData( scalar, buf, type, 0 ));
    IPPI_CALL( func( dst->data.ptr, dst_step, mask->data.ptr,
                     mask_step, size, buf, pix_size ));

    __END__;
}
Пример #2
0
CX_IMPL  void
cxMinMaxLoc( const void* img, double* minVal, double* maxVal,
             CxPoint* minLoc, CxPoint* maxLoc, const void* mask )
{
    static CxFuncTable minmax_tab, minmaxcoi_tab;
    static CxFuncTable minmaxmask_tab, minmaxmaskcoi_tab;
    static int inittab = 0;

    CX_FUNCNAME("cxMinMaxLoc");

    __BEGIN__;

    int type, depth, cn, coi = 0;
    int mat_step, mask_step = 0;
    CxSize size;
    CxMat stub, maskstub, *mat = (CxMat*)img, *matmask = (CxMat*)mask;

    if( !inittab )
    {
        icxInitMinMaxIndxC1RTable( &minmax_tab );
        icxInitMinMaxIndxCnCRTable( &minmaxcoi_tab );
        icxInitMinMaxIndxC1MRTable( &minmaxmask_tab );
        icxInitMinMaxIndxCnCMRTable( &minmaxmaskcoi_tab );
        inittab = 1;
    }
    
    CX_CALL( mat = cxGetMat( mat, &stub, &coi ));

    type = CX_MAT_TYPE( mat->type );
    depth = CX_MAT_DEPTH( type );
    cn = CX_MAT_CN( type );
    size = cxGetMatSize( mat );

    if( cn > 1 && coi == 0 )
        CX_ERROR( CX_StsBadArg, "" );
    
    mat_step = mat->step;

    if( !mask )
    {
        if( size.height == 1 )
            mat_step = CX_STUB_STEP;

        if( CX_MAT_CN(type) == 1 || coi == 0 )
        {
            CxFunc2D_1A4P func = (CxFunc2D_1A4P)(minmax_tab.fn_2d[depth]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, size,
                             minVal, maxVal, minLoc, maxLoc ));
        }
        else
        {
            CxFunc2DnC_1A4P func = (CxFunc2DnC_1A4P)(minmaxcoi_tab.fn_2d[depth]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, size, cn, coi,
                             minVal, maxVal, minLoc, maxLoc ));
        }
    }
    else
    {
        CX_CALL( matmask = cxGetMat( matmask, &maskstub ));

        if( !CX_IS_MASK_ARR( matmask ))
            CX_ERROR( CX_StsBadMask, "" );

        if( !CX_ARE_SIZES_EQ( mat, matmask ))
            CX_ERROR( CX_StsUnmatchedSizes, "" );

        mask_step = matmask->step;

        if( size.height == 1 )
            mat_step = mask_step = CX_STUB_STEP;

        if( CX_MAT_CN(type) == 1 || coi == 0 )
        {
            CxFunc2D_2A4P func = (CxFunc2D_2A4P)(minmaxmask_tab.fn_2d[depth]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, matmask->data.ptr,
                             mask_step, size,
                             minVal, maxVal, minLoc, maxLoc ));
        }
        else
        {
            CxFunc2DnC_2A4P func = (CxFunc2DnC_2A4P)(minmaxmaskcoi_tab.fn_2d[depth]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step,
                             matmask->data.ptr, mask_step, size, cn, coi,
                             minVal, maxVal, minLoc, maxLoc ));
        }
    }

    if( depth < CX_32S || depth == CX_32F )
    {
        if( minVal )
            *minVal = *(float*)minVal;

        if( maxVal )
            *maxVal = *(float*)maxVal;
    }

    __END__;
}
Пример #3
0
CX_IMPL void
icxLogicM( const void* srcimg1, const void* srcimg2,
           void* dstarr, const void* maskarr,
           CxArithmBinMaskFunc2D func )
{
    CX_FUNCNAME( "icxLogicM" );
    
    __BEGIN__;

    int  coi1 = 0, coi2 = 0, coi3 = 0;
    CxMat  srcstub1, *src1 = (CxMat*)srcimg1;
    CxMat  srcstub2, *src2 = (CxMat*)srcimg2;
    CxMat  dststub, *dst = (CxMat*)dstarr;
    CxMat  maskstub, *mask = (CxMat*)maskarr;
    int src_step, dst_step, mask_step; 
    int pix_size;
    CxSize size;

    CX_CALL( src1 = cxGetMat( src1, &srcstub1, &coi1 ));
    CX_CALL( src2 = cxGetMat( src2, &srcstub2, &coi2 ));
    CX_CALL( dst = cxGetMat( dst, &dststub, &coi3 ));
    CX_CALL( mask = cxGetMat( mask, &maskstub ));

    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )
        CX_ERROR( CX_BadCOI, "" );

    if( !CX_IS_MASK_ARR(mask) )
        CX_ERROR_FROM_CODE( CX_StsBadMask );

    if( !CX_ARE_SIZES_EQ( mask, dst ) )
        CX_ERROR_FROM_CODE( CX_StsUnmatchedSizes );

    if( !CX_ARE_SIZES_EQ( src1, src2 ) )
        CX_ERROR_FROM_CODE( CX_StsUnmatchedSizes );

    size = cxGetMatSize( src1 );
    pix_size = icxPixSize[CX_MAT_TYPE(src1->type)];
        
    if( src2->data.ptr != dst->data.ptr )
    {
        if( src1->data.ptr != dst->data.ptr )
        {
            CX_CALL( cxCopy( src2, dst, mask ));
        }
        else
            src1 = src2;
    }
    
    if( !CX_ARE_TYPES_EQ( src1, dst ))
        CX_ERROR_FROM_CODE( CX_StsUnmatchedFormats );

    if( !CX_ARE_SIZES_EQ( src1, dst ))
        CX_ERROR_FROM_CODE( CX_StsUnmatchedSizes );

    src_step = src1->step;
    dst_step = dst->step;
    mask_step = mask->step;
    
    if( CX_IS_MAT_CONT( src1->type & dst->type & mask->type ))
    {
        size.width *= size.height;
        src_step = dst_step = mask_step = CX_STUB_STEP;
        size.height = 1;
    }

    IPPI_CALL( func( src1->data.ptr, src_step, mask->data.ptr, mask_step,
                     dst->data.ptr, dst_step, size, pix_size ));

    __END__;
}
Пример #4
0
CX_IMPL  void
cxAvgSdv( const void* img, CxScalar* _mean, CxScalar* _sdv, const void* mask )
{
    CxScalar mean = {{0,0,0,0}};
    CxScalar sdv = {{0,0,0,0}};

    static CxBigFuncTable meansdv_tab;
    static CxFuncTable meansdvcoi_tab;
    static CxBigFuncTable meansdvmask_tab;
    static CxFuncTable meansdvmaskcoi_tab;
    static int inittab = 0;

    CX_FUNCNAME("cxMean_StdDev");

    __BEGIN__;

    int type, coi = 0;
    int mat_step, mask_step = 0;
    CxSize size;
    CxMat stub, maskstub, *mat = (CxMat*)img, *matmask = (CxMat*)mask;

    if( !inittab )
    {
        icxInitMean_StdDevRTable( &meansdv_tab );
        icxInitMean_StdDevCnCRTable( &meansdvcoi_tab );
        icxInitMean_StdDevMRTable( &meansdvmask_tab );
        icxInitMean_StdDevCnCMRTable( &meansdvmaskcoi_tab );
        inittab = 1;
    }
    
    CX_CALL( mat = cxGetMat( mat, &stub, &coi ));

    type = CX_MAT_TYPE( mat->type );
    size = cxGetMatSize( mat );
    
    mat_step = mat->step;

    if( !mask )
    {
        if( CX_IS_MAT_CONT( mat->type ))
        {
            size.width *= size.height;
            size.height = 1;
            mat_step = CX_STUB_STEP;
        }

        if( CX_MAT_CN(type) == 1 || coi == 0 )
        {
            CxFunc2D_1A2P func = (CxFunc2D_1A2P)(meansdv_tab.fn_2d[type]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, size, mean.val, sdv.val ));
        }
        else
        {
            CxFunc2DnC_1A2P func = (CxFunc2DnC_1A2P)
                (meansdvcoi_tab.fn_2d[CX_MAT_DEPTH(type)]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, size,
                             CX_MAT_CN(type), coi, mean.val, sdv.val ));
        }
    }
    else
    {
        CX_CALL( matmask = cxGetMat( matmask, &maskstub ));

        mask_step = matmask->step;

        if( !CX_IS_MASK_ARR( matmask ))
            CX_ERROR( CX_StsBadMask, "" );

        if( !CX_ARE_SIZES_EQ( mat, matmask ))
            CX_ERROR( CX_StsUnmatchedSizes, "" );

        if( CX_IS_MAT_CONT( mat->type & matmask->type ))
        {
            size.width *= size.height;
            size.height = 1;
            mat_step = mask_step = CX_STUB_STEP;
        }

        if( CX_MAT_CN(type) == 1 || coi == 0 )
        {
            CxFunc2D_2A2P func = (CxFunc2D_2A2P)(meansdvmask_tab.fn_2d[type]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step, matmask->data.ptr,
                             mask_step, size, mean.val, sdv.val ));
        }
        else
        {
            CxFunc2DnC_2A2P func = (CxFunc2DnC_2A2P)
                (meansdvmaskcoi_tab.fn_2d[CX_MAT_DEPTH(type)]);

            if( !func )
                CX_ERROR( CX_StsBadArg, cxUnsupportedFormat );

            IPPI_CALL( func( mat->data.ptr, mat_step,
                             matmask->data.ptr, mask_step,
                             size, CX_MAT_CN(type), coi, mean.val, sdv.val ));
        }
    }

    __END__;

    if( _mean )
        *_mean = mean;

    if( _sdv )
        *_sdv = sdv;
}