I am trying to view and preprocess a .mhd and .raw image types on jupyter notebook, but I am getting a syntax error.

0 votes
import SimpleITK as sitk
import numpy as np
'''
This funciton reads a '.mhd' file using SimpleITK and return the image array, origin and spacing of the image.
'''

def load_itk('C:/Users/tek/SampleNodule'):
    # Reads the image using SimpleITK
    itkimage = sitk.ReadImage('C:/Users/tek/SampleNodule')

    # Convert the image to a  numpy array first and then shuffle the dimensions to get axis in the order z,y,x
    ct_scan = sitk.GetArrayFromImage(itkimage)

    # Read the origin of the ct_scan, will be used to convert the coordinates from world to voxel and vice versa.
    origin = np.array(list(reversed(itkimage.GetOrigin())))

    # Read the spacing along each dimension
    spacing = np.array(list(reversed(itkimage.GetSpacing())))

    return ct_scan, origin, spacing

# finally I am getting the following error and I can't fix it as i am novice for machine learing in python.
File "<ipython-input-4-5829076b62cd>", line 7
    def load_itk('C:/Users/tek/SampleNodule'):
                                           ^
SyntaxError: invalid syntax
Nov 4 in Python by tekle
• 120 points

edited Nov 4 by Omkar 73 views

1 answer to this question.

0 votes

Hey @tekle, 

You cannot use a string in the function definition. You can only use an object and then pass a string to it. Something like this:

def samp(sample):
    im = sitk.ReadImage("C:/Users/omkar/Downloads/images.jpg")

samp("C:/Users/omkar/Downloads/images.jpg")
answered Nov 4 by Payal
thank you very much, sir. It helps me a lot. and you saved me from plenty of searches on google.

Related Questions In Python

0 votes
1 answer

Why am I getting a error when I am printing two different data types in python?

different data type is being used. that ...READ MORE

answered Mar 6 in Python by Mohammad
• 3,060 points
49 views
+2 votes
0 answers

I am trying to create mininet, but I cannot ping all host and switch

I am trying to do mininet environment ...READ MORE

Aug 4 in Python by Jiun-Jung
• 140 points
55 views
+1 vote
1 answer
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 346 views
+4 votes
6 answers
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14 in Python by Junaid
44 views