lokesh andhavarapu
lokesh andhavarapu

Reputation: 11

OpenCV + Python - NameError: name 'imSize' is not defined

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

Upvotes: 0

Views: 1025

Answers (1)

PixelPioneer
PixelPioneer

Reputation: 4170

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.

Upvotes: 1

Related Questions