0

I am using OpenCV for image processing. In which, I am getting these errors please suggest what to do, below is my code:

import dicom
import Image
import ImageOps

meta=dicom.read_file("E:\A_SHIVA\ANANADAN\IM_0.dcm") 
imHeight=meta.Rows
imWidth=meta.Columns 
imSize=(imWidth,imHeight)
TT=Image.frombuffer("L",imSize,meta.PixelData,"raw","L",0,1)
TT.save("testOUTPUT.tiff","TIFF",compression="none")

The error is below:

Traceback (most recent call last):
  File "C:\Users\sairamsystem\AppData\Local\Enthought\Canopy\User\lib\site-packages\IPython\core\interactiveshell.py", line 3066, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-8-640c37dc4648>", line 1, in <module>
    TT=Image.frombuffer('L',imSize,meta.PixelData,"raw","L",0,1)
NameError: name 'imSize' is not defined
1
  • 1
    Welcome to StackOverflow! Please change your question to something like "Error when using OpenCV for image processing" and add a sentence like 'I am getting the following error {error}. How can I solve this problem? Thank you!'. That improves the quality of your post. Commented Jul 25, 2016 at 9:02

1 Answer 1

1

The code is fine. It worked for me. The name error exception happened because it could not find imSize variable, which means it never got made. This can only happen when you haven't read the Dicom file properly, so try changing the path and printing the variable 'meta' to see if it has any value. After reading the file also print and check if meta.Rows and meta.Columns are having the correct values or not.

Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me. Just check if the path you are using is right. After read_file try printing the meta variable to see if it has any value. Then print meta.Rows to see if it gives you some value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.