Skip to content

A redundant logic in distanceTransform. #23060

@issuefiler

Description

@issuefiler

Version

OpenCV 4.7.0.

Issue

if( need_labels )
{
CV_Assert( labelType == DIST_LABEL_PIXEL || labelType == DIST_LABEL_CCOMP );
_labels.create(src.size(), CV_32S);
labels = _labels.getMat();
maskSize = CV_DIST_MASK_5;
}
float _mask[5] = {0};
if( maskSize != CV_DIST_MASK_3 && maskSize != CV_DIST_MASK_5 && maskSize != CV_DIST_MASK_PRECISE )
CV_Error( CV_StsBadSize, "Mask size should be 3 or 5 or 0 (precise)" );
if( distType == CV_DIST_C || distType == CV_DIST_L1 )
maskSize = !need_labels ? CV_DIST_MASK_3 : CV_DIST_MASK_5;
else if( distType == CV_DIST_L2 && need_labels )
maskSize = CV_DIST_MASK_5;

if( need_labels ) 
{ 
    ……
    maskSize = CV_DIST_MASK_5; 
} 

The maskSize is set to CV_DIST_MASK_5 if (need_labels). Meaning, the follow-up code

if( distType == CV_DIST_C || distType == CV_DIST_L1 ) 
    maskSize = !need_labels ? CV_DIST_MASK_3 : CV_DIST_MASK_5; 
else if( distType == CV_DIST_L2 && need_labels ) 
    maskSize = CV_DIST_MASK_5; 

does the same as

if((distType == CV_DIST_C || distType == CV_DIST_L1) && !need_labels) 
    maskSize = CV_DIST_MASK_3;

.


  • The redundant code should be removed.
  • The maskSize being set to CV_DIST_MASK_5 if (need_labels), no matter what maskSize is provided, is undocumented behavior, and should be properly documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: documentationDocumentation fix or updatecleanupCode cleanup (e.g, drop legacy C-API, legacy unmaintained code)feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions