Metadata extraction from image header

Hi,

I stored some information in the header of my tiff images that I would like to retrieve in a custom module. In matlab I can do something like this:

iminfo = imfinfo(CurrentImagePath);
descrip = iminfo.ImageDescription;

descrip is now a string containing what was in the header. Does anybody know how I can do this in python?

Thanks in advance! John

Okay, I’ve figured out my own question and it’s pretty simple, but I’ll post a reply in case anyone has a similar question:

– open an image with the built-in python file reader function ‘open’ using the ‘rt’ or read text file mode

img = open(‘20101103glut4insulin20xa_B01f01ch0.tif’, “rt”)

– now read the first 1000 characters

x1 = img.read(1000)

– the header info appears to be between characters 190 and about 750

x1[190:750]
'Experiment base name:20101103glut4insulin20x\nExperiment set:PAD_48hr\n2 plates of gfp-glut4 CHO cells induced to translocate in response to insulin\nExposure: 200 ms\nBinning: 1 x 1\nRegion: 1280 x 1024, offset at (0, 0)\nSubtract: Off\nShading: correction performed\n … etc.

-john