Problems in use .nrrd format from 3d slicer in python.

Hi.
I’m dealing with MR DICOM now.
In order to see the screen like the image of the slice obtained from the 3D Slicer as shown in the below picture(fig1.) in Python, I saved it in .nrrd format through the ‘save’ function in the 3d slicer.

fig1.

fig1.

fig2.

fig2.

Then I looked at the 0th slice using the python code below and it is different(fig3.) from slice in 3D Slicer.

import nrrd
data,_ = nrrd.read('C:/Users/user/Desktop/slicer/602 3D T1 
TFE AX F GD.nrrd')

plt.subplot(1,1,1)
plt.imshow(data.T[0], cmap="gray")
plt.axis('off')

fig3.

fig3.

The reason I want to get a slice of the 3D Slicer is that I want to get a slightly tilted volume as shown in fig2.
Thank you for your help in this area.

This is normal - Slicer shows patient coordinates and it looks like your images are slightly rotated with respect to patient.

https://www.slicer.org/wiki/Coordinate_systems

You can change this in slicer with the button labelled 4 in this image.

Thank you for your reply!

I used the link mentioned in the reply to confirm that the image is changing.

In addition, the link says that the volume is not transformed, but is a plane match orientation of volume axes. Is this possible in Python?

    for con in contours:
    index = np.array(con['uid'])
    num = int(con['number'])
    
    for c,i in zip(con['contours'],range(len(index))):
        idf = uids.index(index[i])
        origin = slices[idf+1].ImageOrientationPatient
        pos_r = slices[idf+1].ImagePositionPatient[1]
        pos_c = slices[idf+1].ImagePositionPatient[0]
        spacing_r = slices[idf+1].PixelSpacing[1]
        spacing_c = slices[idf+1].PixelSpacing[0]
        nodes = np.array(c).reshape((-1, 3))
        r = (np.inner((nodes[:, 1] - pos_r),origin[0]) + np.inner((nodes[:,1] - pos_r),origin[3])) / spacing_r
        c = (np.inner((nodes[:, 0] - pos_c),origin[1]) + np.inner((nodes[:,0] - pos_c),origin[4])) / spacing_c 
        rr, cc = polygon(r, c)
        label[idf, rr, cc] = num+1

In fact, using the code(read RT Structure’s Contour) above, I would like to reposition the misplaced contour of the structure as shown in the photo.

In my opinion, if I replace the tilted image before transforming it in the slicer, the contour and image will match.

Thank you for answering the previous question, and I would be grateful if you could give me a hint once more.

Hi Sangkyun @11131 -

I’ll admit I don’t really understand the question fully, but I can say that if you are working with RT struct datasets I suggest using the SlicerRT extension for 3D Slicer. This will handle the coordinate systems between contours and reference images according to the standard. You should also be able to convert and resample the underlying data using python. Hope that helps!

-Steve

What I want is to know what kind of processing in python to see images like fig1. And fig2.