### Bug Description there's a bug in handling grayscale images with a singleton first dimension. The current code incorrectly permutes dimensions after stacking.