title: Extracting scale bar from .tif image metadata using PIL TiffTags
body: <p>I'm new to Python, and am hoping to extract scale information from an electron microscopy (.tif) image. </p>
  
  <p>When I open the file in Notepad and scroll to the bottom, I see a title "[Scan]" and an item underneath it "PixelWidth=3.10059e-010". </p>
  
  <p>I'd like to read this value in Python and use it as a calibration factor for measuring physical distances within the image. </p>
  
  <p>I found a promising approach using PIL (<a href="https://stackoverflow.com/a/46910779/10244370">https://stackoverflow.com/a/46910779/10244370</a>) but encounter an error when running the recommended code.</p>
  
  <pre><code>from PIL import Image
  from PIL.TiffTags import TAGS
  
  with Image.open(imagetoanalyze) as img:
      meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}
  </code></pre>
  
  <p>I expected this to create an object "meta_dict" containing strings like "PixelWidth" and floats like "3.10059e-010". </p>
  
  <p>Instead I see:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-62-4ea0187b2b49&gt;", line 2, in &lt;module&gt;
      meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}
  
    File "&lt;ipython-input-62-4ea0187b2b49&gt;", line 2, in &lt;dictcomp&gt;
      meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}
  
  KeyError: 34682
  </code></pre>
  
  <p>Clearly I'm doing something wrong. Any help would be greatly appreciated. Thank you!</p>