title: AttributeError: 'FileDataset' object has no attribute 'PixelSpacing'
body: <p>I want to convert the filetype of a series of images from .dcm to .mha. Following is my code:</p>
  
  <pre><code>import numpy
  import pydicom
  import os
  PathDicom ='./DicomResource'
  lstFilesDCM = []
  for dirName, subdirList, fileList in os.walk(PathDicom):
  for filename in fileList:
      if '.dcm' in filename.lower():
          lstFilesDCM.append(os.path.join(dirName, filename))
  
  RefDs = pydicom.read_file(lstFilesDCM[0])
  ConstPixelDims = (int(RefDs.Rows), int(RefDs.Columns), len(lstFilesDCM))
  #RefDs.PixelSpacing = 0
  ConstPixelSpacing = (float(RefDs.PixelSpacing[0]), 
  float(RefDs.PixelSpacing[1]), float(RefDs.SliceThickness))
  info = ConstPixelDims + ConstPixelSpacing
  f = open('info.txt', 'w')
  for n in info:
      f.write(str(n)+' ')
  f.close()
  location = []
  for i in range(len(lstFilesDCM)):
      ds = pydicom.read_file(lstFilesDCM[i])
      location.append(ds.SliceLocation)
  location.sort()
  ArrayDicom = numpy.zeros((len(lstFilesDCM), RefDs.Rows, RefDs.Columns), 
  dtype=RefDs.pixel_array.dtype)
  for filenameDCM in lstFilesDCM:
      ds = pydicom.read_file(filenameDCM)
      ArrayDicom[location.index(ds.SliceLocation), :, :] = ds.pixel_array
  ds = ArrayDicom.tostring()
  f = open('1.mha', 'wb')
  f.write(ds)
  f.close()
  </code></pre>
  
  <p>With this, I am getting following error:</p>
  
  <blockquote>
    <p>AttributeError: 'FileDataset' object has no attribute 'PixelSpacing'</p>
  </blockquote>
  
  <p>I also tried adding <code>RefDs.PixelSpacing = 0</code>. It throws next error. 
  <a href="https://i.stack.imgur.com/0IZTW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0IZTW.png" alt="Error"></a></p>
  
  <p>Is there anyone can help me to solve the problem?</p>