Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4647 closed defect (fixed)

GDALRasterPolygonEnumerator does not merge polygons correctly when nConnectedness = 8

Reported by: ctoney Owned by: warmerdam
Priority: normal Milestone: 1.9.1
Component: Algorithms Version: 1.9.0
Severity: normal Keywords: Raster Polygon Enumerator
Cc: Kyle Shannon

Description

When nConnectedness = 8 (diagonal pixels considered connected), GDALRasterPolygonEnumerator does not merge some diagonally connected pixels into the same polygon.

The attached graphic shows two examples of connected pixels that were not merged into a single polygon. In the graphic, yellow and blue pixels have the same value and should be enumerated as polygons when connected diagonally or along sides. All other pixels are masked out from polygon enumeration.

The logic in GDALRasterPolygonEnumerator::ProcessLine is incomplete for nConnectedness = 8. Some additional checks for diagonal connectedness are needed with calls to MergePolygon. The attached file gdalrasterpolygonenumerator_fix.cpp contains the additional checks in ProcessLine - all changes are in lines 188-246. The fixed code has been tested on several examples and seems to work on all possible pixel configurations with diagonal connectedness.

Similar changes are probably needed in gdalrasterfpolygonenumerator.cpp (the version using float buffers).

Attachments (4)

polygon_enum_8connect_fail.png (145.9 KB ) - added by ctoney 12 years ago.
gdalrasterpolygonenumerator_fix.cpp (8.8 KB ) - added by ctoney 12 years ago.
4647.patch (1.8 KB ) - added by Kyle Shannon 12 years ago.
patch against trunk r24372
polygonize_test.tif (2.3 KB ) - added by ctoney 12 years ago.

Download all attachments as: .zip

Change History (11)

by ctoney, 12 years ago

comment:1 by Kyle Shannon, 12 years ago

Cc: Kyle Shannon added

comment:2 by Kyle Shannon, 12 years ago

Chris, what version are you using?

by Kyle Shannon, 12 years ago

Attachment: 4647.patch added

patch against trunk r24372

comment:3 by Kyle Shannon, 12 years ago

Added patch instead of full file.

comment:4 by ctoney, 12 years ago

Version: unspecified1.9.0

comment:5 by warmerdam, 12 years ago

Milestone: 1.9.1
Status: newassigned

It would be really nice to have a small test file that demonstrates the problem so we could extend the test suite. See samples in autotest/alg/

I also imagine this needs to be applied to the new floating point copy of the polygonization algorithm.

comment:6 by warmerdam, 12 years ago

Resolution: fixed
Status: assignedclosed

I have applied the change in trunk (r24379) and 1.9 (r24380) to the integer and floating point versions of the algorithm. The floating point side is untested.

by ctoney, 12 years ago

Attachment: polygonize_test.tif added

comment:7 by ctoney, 12 years ago

I've attached a small test file that demonstrates the problem of some diagonally connected polygons not merged. Pixel values are 6 or nodata.

Note: See TracTickets for help on using tickets.