The code looks alright.
The reference implementation and your approach should yield the same result, if you are directly indexing the array, since this dimension will be gone.
However, your approach should be better, since img_ab will have the right shape form the beginning.
Could you load a test image and just verify the indexing by visualizing the results and check that you see the expected LAB channels?