Nibabel orientation issue

Background: I am trying to generate mesh of lesion segmentation from NIFTI file, so I am succesfully generated it with measure.marching_cubes_lewiner, in advance transformed NIFTI to ndarray.

However, i tried to check the orientation of the mesh, and found out that it is wrong - z coordinate is stretching the brain mesh

I consider that the problem is in nibabel orientation, because while loading images with nib.load:

def show_slices(stack):
    fig, axes = plt.subplots(1, len(stack))
    for i, slice in enumerate(stack):
        axes[i].imshow(slice, cmap="gray")

sample_stack(array_img, brain_mask_img)

i have following orientation:

How to resolve issue with such orientation and allign it with FOV window, so all coordinates wouldn’t stretch meshes?

This doesn’t appear to have anything to do with orientation. It looks like an issue with scaling in your 3D plot. Note the axes have different ranges, but are stretched to roughly the same distance.

If this is still an issue, you can crop the x and y dimensions or zero-pad the z dimension until you have a cube. If you need to return that to an image, you’ll need to fiddle with the translation vector in the affine, but if you’re only doing this in the ndarray, there’s no need to worry about that.

Thanks @effigies, Yes it seems plotly generates cubic coords, while dims ratio stays nifti native. aspectratio did the job.