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, 2019 in Python by tekle
• 120 points

edited Nov 4, 2019 by Omkar 539 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, 2019 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
0 answers

I am trying to install PyBase64 on my python 3.8. But I end up with the following error:

$ pip install pybase ERROR: Could not find ...READ MORE

Mar 24 in Python by Nishant
• 210 points
230 views
0 votes
0 answers

I am trying to install os-win on my python 3.8. But I end up with the following error:

ERROR: Command errored out with exit status ...READ MORE

Mar 24 in Python by Nishant
• 210 points
402 views
0 votes
1 answer

I am trying to install visualize on my python 3.8 but i end up with the followinf error.

Hi@Avinash, I think the module name is visualization ...READ MORE

answered Apr 27 in Python by MD
• 33,540 points
72 views
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, 2019 in Python by Mohammad
• 3,230 points
92 views
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,075 views
0 votes
0 answers
+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, 2019 in Python by Junaid
113 views