BUG: make ndimage.label properly merge adjacent objects (fixes #3025)

ndimage.label() uses a table of label values that should be merged in
a postprocess.  The logic updating this table was faulty.  In
particular, if objects A and B were to be marked for mergin, having
already been marked to merge to C and D, respectively, the implied
merge of C and D was not being inferred.

(cherry picked from commit 04a2dda39d3b0bd5d35c8a606199cd13d87fd377)
add test for #3025

(cherry picked from commit 52d8aff08645f511ba8664e2383d856230f52baf)
Merge pull request #3050 from pv/bp-3033

Backport #3033 to 0.13.x