BUG: make ndimage.label properly merge adjacent objects (fixes #3025)
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.

aeklant/scipy,hainm/scipy,Eric89GXL/scipy,anielsen001/scipy,person142/scipy,Shaswat27/scipy,maciejkula/scipy,ilayn/scipy,rgommers/scipy,minhlongdo/scipy,ndchorley/scipy,fredrikw/scipy,gef756/scipy,ortylp/scipy,futurulus/scipy,zaxliu/scipy,mingwpy/scipy,efiring/scipy,josephcslater/scipy,jseabold/scipy,arokem/scipy,raoulbq/scipy,witcxc/scipy,njwilson23/scipy,mhogg/scipy,vberaudi/scipy,Newman101/scipy,giorgiop/scipy,vhaasteren/scipy,efiring/scipy,aarchiba/scipy,mortonjt/scipy,jamestwebber/scipy,arokem/scipy,vanpact/scipy,gdooper/scipy,chatcannon/scipy,mdhaber/scipy,niknow/scipy,matthew-brett/scipy,lhilt/scipy,fredrikw/scipy,andyfaff/scipy,futurulus/scipy,pnedunuri/scipy,mingwpy/scipy,richardotis/scipy,haudren/scipy,gef756/scipy,pbrod/scipy,FRidh/scipy,aarchiba/scipy,fernand/scipy,sauliusl/scipy,anntzer/scipy,pyramania/scipy,jor-/scipy,andim/scipy,Newman101/scipy,anntzer/scipy,befelix/scipy,vanpact/scipy,maniteja123/scipy,zxsted/scipy,trankmichael/scipy,witcxc/scipy,raoulbq/scipy,Gillu13/scipy,maciejkula/scipy,nvoron23/scipy,Stefan-Endres/scipy,aman-iitj/scipy,Newman101/scipy,gdooper/scipy,maniteja123/scipy,aman-iitj/scipy,aeklant/scipy,fredrikw/scipy,futurulus/scipy,pyramania/scipy,niknow/scipy,mhogg/scipy,mdhaber/scipy,Shaswat27/scipy,ChanderG/scipy,hainm/scipy,jakevdp/scipy,maniteja123/scipy,aeklant/scipy,lukauskas/scipy,aman-iitj/scipy,dominicelse/scipy,jakevdp/scipy,zaxliu/scipy,hainm/scipy,jonycgn/scipy,dch312/scipy,pizzathief/scipy,andim/scipy,pschella/scipy,andim/scipy,newemailjdm/scipy,chatcannon/scipy,WillieMaddox/scipy,richardotis/scipy,Eric89GXL/scipy,ogrisel/scipy,cpaulik/scipy,zerothi/scipy,kleskjr/scipy,surhudm/scipy,felipebetancur/scipy,jseabold/scipy,vigna/scipy,mhogg/scipy,josephcslater/scipy,pbrod/scipy,larsmans/scipy,richardotis/scipy,WillieMaddox/scipy,WarrenWeckesser/scipy,vigna/scipy,kalvdans/scipy,Gillu13/scipy,richardotis/scipy,jor-/scipy,mortonjt/scipy,zxsted/scipy,WarrenWeckesser/scipy,lhilt/scipy,rgommers/scipy,WarrenWeckesser/scipy,cpaulik/scipy,haudren/scipy,sauliusl/scipy,pbrod/scipy,grlee77/scipy,jonycgn/scipy,pizzathief/scipy,ales-erjavec/scipy,Dapid/scipy,gfyoung/scipy,cpaulik/scipy,zerothi/scipy,hainm/scipy,futurulus/scipy,jsilter/scipy,nonhermitian/scipy,giorgiop/scipy,sauliusl/scipy,person142/scipy,tylerjereddy/scipy,rmcgibbo/scipy,anntzer/scipy,mhogg/scipy,Gillu13/scipy,giorgiop/scipy,rmcgibbo/scipy,sonnyhu/scipy,nvoron23/scipy,vhaasteren/scipy,maniteja123/scipy,aman-iitj/scipy,aarchiba/scipy,woodscn/scipy,Stefan-Endres/scipy,anielsen001/scipy,aman-iitj/scipy,chatcannon/scipy,ChanderG/scipy,sonnyhu/scipy,witcxc/scipy,nvoron23/scipy,matthewalbani/scipy,anntzer/scipy,witcxc/scipy,chatcannon/scipy,jakevdp/scipy,nvoron23/scipy,niknow/scipy,witcxc/scipy,argriffing/scipy,efiring/scipy,giorgiop/scipy,gertingold/scipy,ChanderG/scipy,kalvdans/scipy,matthewalbani/scipy,rgommers/scipy,rgommers/scipy,kleskjr/scipy,mgaitan/scipy,vberaudi/scipy,Shaswat27/scipy,mortonjt/scipy,vanpact/scipy,pizzathief/scipy,mgaitan/scipy,lhilt/scipy,Srisai85/scipy,bkendzior/scipy,zxsted/scipy,sriki18/scipy,scipy/scipy,petebachant/scipy,jjhelmus/scipy,aarchiba/scipy,jseabold/scipy,jakevdp/scipy,raoulbq/scipy,josephcslater/scipy,ndchorley/scipy,jamestwebber/scipy,ales-erjavec/scipy,grlee77/scipy,gef756/scipy,sauliusl/scipy,njwilson23/scipy,zerothi/scipy,fernand/scipy,futurulus/scipy,aeklant/scipy,felipebetancur/scipy,petebachant/scipy,e-q/scipy,gdooper/scipy,sonnyhu/scipy,njwilson23/scipy,jseabold/scipy,ndchorley/scipy,trankmichael/scipy,rmcgibbo/scipy,matthew-brett/scipy,ortylp/scipy,scipy/scipy,vigna/scipy,jakevdp/scipy,gertingold/scipy,Shaswat27/scipy,vigna/scipy,arokem/scipy,petebachant/scipy,jsilter/scipy,mdhaber/scipy,felipebetancur/scipy,ortylp/scipy,vberaudi/scipy,maciejkula/scipy,Kamp9/scipy,endolith/scipy,maciejkula/scipy,Kamp9/scipy,fredrikw/scipy,pschella/scipy,zerothi/scipy,woodscn/scipy,pizzathief/scipy,futurulus/scipy,Eric89GXL/scipy,surhudm/scipy,jor-/scipy,gertingold/scipy,pnedunuri/scipy,sriki18/scipy,andim/scipy,Shaswat27/scipy,felipebetancur/scipy,rgommers/scipy,fernand/scipy,Newman101/scipy,mingwpy/scipy,fernand/scipy,vhaasteren/scipy,trankmichael/scipy,hainm/scipy,mortonjt/scipy,ogrisel/scipy,zaxliu/scipy,mikebenfield/scipy,nonhermitian/scipy,arokem/scipy,hainm/scipy,pyramania/scipy,andyfaff/scipy,Kamp9/scipy,FRidh/scipy,cpaulik/scipy,ndchorley/scipy,piyush0609/scipy,zaxliu/scipy,e-q/scipy,zxsted/scipy,surhudm/scipy,e-q/scipy,chatcannon/scipy,lukauskas/scipy,ortylp/scipy,behzadnouri/scipy,Dapid/scipy,argriffing/scipy,fernand/scipy,zaxliu/scipy,jamestwebber/scipy,mortada/scipy,haudren/scipy,woodscn/scipy,ilayn/scipy,felipebetancur/scipy,jamestwebber/scipy,anntzer/scipy,cpaulik/scipy,piyush0609/scipy,mtrbean/scipy,sriki18/scipy,pnedunuri/scipy,matthewalbani/scipy,njwilson23/scipy,pyramania/scipy,pbrod/scipy,woodscn/scipy,andyfaff/scipy,larsmans/scipy,newemailjdm/scipy,pnedunuri/scipy,anielsen001/scipy,tylerjereddy/scipy,endolith/scipy,efiring/scipy,WillieMaddox/scipy,andyfaff/scipy,mhogg/scipy,zxsted/scipy,njwilson23/scipy,nmayorov/scipy,ChanderG/scipy,nonhermitian/scipy,dch312/scipy,pnedunuri/scipy,vhaasteren/scipy,vberaudi/scipy,aeklant/scipy,tylerjereddy/scipy,vigna/scipy,mtrbean/scipy,ales-erjavec/scipy,behzadnouri/scipy,grlee77/scipy,Gillu13/scipy,mikebenfield/scipy,Dapid/scipy,jor-/scipy,matthew-brett/scipy,mortada/scipy,Stefan-Endres/scipy,gfyoung/scipy,befelix/scipy,jsilter/scipy,argriffing/scipy,ogrisel/scipy,pschella/scipy,larsmans/scipy,tylerjereddy/scipy,pschella/scipy,mikebenfield/scipy,sonnyhu/scipy,fredrikw/scipy,giorgiop/scipy,sriki18/scipy,WarrenWeckesser/scipy,ogrisel/scipy,matthewalbani/scipy,zxsted/scipy,ortylp/scipy,e-q/scipy,gdooper/scipy,piyush0609/scipy,sriki18/scipy,matthew-brett/scipy,sriki18/scipy,niknow/scipy,ogrisel/scipy,person142/scipy,endolith/scipy,nonhermitian/scipy,scipy/scipy,mgaitan/scipy,Kamp9/scipy,apbard/scipy,befelix/scipy,kleskjr/scipy,grlee77/scipy,trankmichael/scipy,cpaulik/scipy,mingwpy/scipy,jjhelmus/scipy,mikebenfield/scipy,vanpact/scipy,woodscn/scipy,matthew-brett/scipy,person142/scipy,mhogg/scipy,mingwpy/scipy,behzadnouri/scipy,mikebenfield/scipy,woodscn/scipy,jseabold/scipy,gef756/scipy,kleskjr/scipy,WarrenWeckesser/scipy,Dapid/scipy,WillieMaddox/scipy,lukauskas/scipy,perimosocordiae/scipy,pbrod/scipy,larsmans/scipy,ChanderG/scipy,person142/scipy,fernand/scipy,nvoron23/scipy,piyush0609/scipy,niknow/scipy,gfyoung/scipy,gef756/scipy,rmcgibbo/scipy,pbrod/scipy,bkendzior/scipy,matthewalbani/scipy,gef756/scipy,befelix/scipy,jonycgn/scipy,gfyoung/scipy,endolith/scipy,andim/scipy,newemailjdm/scipy,behzadnouri/scipy,Dapid/scipy,argriffing/scipy,FRidh/scipy,Kamp9/scipy,endolith/scipy,minhlongdo/scipy,scipy/scipy,zerothi/scipy,nmayorov/scipy,jamestwebber/scipy,Eric89GXL/scipy,mgaitan/scipy,sonnyhu/scipy,anntzer/scipy,pnedunuri/scipy,vanpact/scipy,richardotis/scipy,maciejkula/scipy,Stefan-Endres/scipy,kalvdans/scipy,argriffing/scipy,befelix/scipy,vhaasteren/scipy,andyfaff/scipy,mortada/scipy,kalvdans/scipy,apbard/scipy,nonhermitian/scipy,FRidh/scipy,Srisai85/scipy,vanpact/scipy,gertingold/scipy,Eric89GXL/scipy,mdhaber/scipy,petebachant/scipy,anielsen001/scipy,jjhelmus/scipy,vberaudi/scipy,lhilt/scipy,gertingold/scipy,dch312/scipy,perimosocordiae/scipy,lhilt/scipy,vberaudi/scipy,jjhelmus/scipy,mgaitan/scipy,tylerjereddy/scipy,aman-iitj/scipy,mortada/scipy,ales-erjavec/scipy,WillieMaddox/scipy,Dapid/scipy,larsmans/scipy,lukauskas/scipy,sauliusl/scipy,bkendzior/scipy,mortada/scipy,zerothi/scipy,jonycgn/scipy,piyush0609/scipy,mingwpy/scipy,efiring/scipy,ilayn/scipy,apbard/scipy,rmcgibbo/scipy,newemailjdm/scipy,ales-erjavec/scipy,scipy/scipy,jjhelmus/scipy,mgaitan/scipy,petebachant/scipy,ales-erjavec/scipy,niknow/scipy,Srisai85/scipy,mtrbean/scipy,raoulbq/scipy,mtrbean/scipy,Shaswat27/scipy,minhlongdo/scipy,jor-/scipy,pschella/scipy,nvoron23/scipy,raoulbq/scipy,newemailjdm/scipy,ndchorley/scipy,minhlongdo/scipy,sonnyhu/scipy,Srisai85/scipy,FRidh/scipy,perimosocordiae/scipy,lukauskas/scipy,behzadnouri/scipy,anielsen001/scipy,ilayn/scipy,argriffing/scipy,pyramania/scipy,FRidh/scipy,andim/scipy,dominicelse/scipy,ilayn/scipy,haudren/scipy,mtrbean/scipy,jsilter/scipy,jseabold/scipy,larsmans/scipy,grlee77/scipy,Stefan-Endres/scipy,ndchorley/scipy,apbard/scipy,behzadnouri/scipy,bkendzior/scipy,chatcannon/scipy,perimosocordiae/scipy,richardotis/scipy,WillieMaddox/scipy,mdhaber/scipy,ilayn/scipy,rmcgibbo/scipy,nmayorov/scipy,jsilter/scipy,mortonjt/scipy,Stefan-Endres/scipy,vhaasteren/scipy,piyush0609/scipy,petebachant/scipy,apbard/scipy,newemailjdm/scipy,jonycgn/scipy,perimosocordiae/scipy,nmayorov/scipy,kleskjr/scipy,aarchiba/scipy,maniteja123/scipy,lukauskas/scipy,zaxliu/scipy,endolith/scipy,josephcslater/scipy,Gillu13/scipy,andyfaff/scipy,surhudm/scipy,dch312/scipy,scipy/scipy,dominicelse/scipy,minhlongdo/scipy,haudren/scipy,sauliusl/scipy,arokem/scipy,haudren/scipy,ChanderG/scipy,e-q/scipy,maniteja123/scipy,Srisai85/scipy,njwilson23/scipy,ortylp/scipy,Kamp9/scipy,raoulbq/scipy,josephcslater/scipy,kalvdans/scipy,gfyoung/scipy,kleskjr/scipy,Srisai85/scipy,Newman101/scipy,surhudm/scipy,dominicelse/scipy,mortada/scipy,mdhaber/scipy,trankmichael/scipy,felipebetancur/scipy,nmayorov/scipy,trankmichael/scipy,bkendzior/scipy,jonycgn/scipy,anielsen001/scipy,giorgiop/scipy,Eric89GXL/scipy,dch312/scipy,WarrenWeckesser/scipy,mtrbean/scipy,surhudm/scipy,efiring/scipy,perimosocordiae/scipy,minhlongdo/scipy,gdooper/scipy,Gillu13/scipy,Newman101/scipy,pizzathief/scipy,fredrikw/scipy,mortonjt/scipy,dominicelse/scipy