Skip to content

distanceTransform() give wrong results for large images #22732

@TheoShouten

Description

@TheoShouten

System Information

OpenCV 4.6.0
minGW 64 bits with GCC 12.2.0
Windows 10

Detailed description

distanceTransform( in, dist, DIST_L2,DIST_MASK_PRECISE,CV_32F ); give good results for small square images but not for large ones above 4k by 4k. For column numbers above 4k it often gives black pixels an ED of 1.0 in stead of 0.0.

Details

i001

Details

i000

Steps to reproduce

Mat in = imread(name, IMREAD_UNCHANGED);
int numpixels = in.cols*in.rows;
    Mat dist(in.rows,in.cols,CV_32F);
    distanceTransform( in, dist, DIST_L2,DIST_MASK_PRECISE,CV_32F );
float* pf = (float*)dist.data;
   for(i=0;i<numpixels;i++) {if(in.data[i]==0 && pf[i] != 0.0)
        printf("y %4d x %4d in: %2d out: %f \n", (int) i/in.cols,i%in.rows,in.data[i],pf[i]);

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions