Label3d

This pull request features two things:

1. 2D labelling refactoring. This has resulted in:
   * Higher readability of the code by breaking large functions into smaller ones.
   * More exhaustive documentation of the code.
   * Better performance (I have observed a 50% time reduction in 2D).

2. Addition of support for 3D arrays (including tests)

And as a bonus, an undocumented limitation has been removed (degenerated 2D arrays of shape (x, 1) where x > 1 didn't work with the algorithm). Tests cases for this were also added.

This PR #1208 has been there before and grew quite long as I have progressed to satisfy requirements of @stefanv and @jnl. And as these gentlemen have suggested, I have closed it and created this new one.