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 2,835 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")

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, 2020 in Python by Nishant
• 210 points
0 votes
1 answer

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

I have the same issue and is ...READ MORE

answered Sep 6, 2020 in Python by anonymous
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, 2020 in Python by MD
• 95,440 points
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,052 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
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
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP