File Exchange

image thumbnail

Read .dm3 and .dm4 image files

version 1.1.0.0 (4.54 KB) by Fred Sigworth
Read Digital Micrograph files for electron microscopy

15 Downloads

Updated 20 Sep 2013

View License

Electron microscope images and image stacks are stored in a proprietary fromat by Digital Micrograph (Gatan Inc.). This function reads version 3 and also the new 64-bit version 4 files. This replaces the ReadDM3 function in my previous post #27021, "Imagic, MRC and DM3 file i/o"

Comments and Ratings (13)

fucai zhang

Subin Lee

Hello I'm Subin. When I try to open dm4 image, the error message comes up which is saying "Error using reshape
Size vector must have at least two elements.Error in ReadDMFile (line 104) m=reshape(output{6},[xdim ydim zdim]);"
Would you please let me know how to solve this?

One more note: the ReadMRC function in the code below is available in another of my File Exchange posts.

Dear Shaf,

The returned image variable is a 2-d array of numbers. The function returns the exact numeric values and type that was written there by Digital Micrograph. The relationship with image intensity depends on the scaling of the camera and whether dark-image subtraction has been done. You can view it with Matlab image display functions, e.g.

m=ReadDMFile('myfilename.dm4');
colormap gray % set up a grayscale display
imagesc(m);

You can look at a histogram of the image first by making sure it's in floating point,

ms=single(m);

then draw a 1000-bin histogram of all pixels,
hist(ms(:),1000).

You can write out the image by first constraining it to the range 0..255 so it will fit a standard 8-bit format. Here is autoscaling to max and min values:

msc=255*(ms-min(ms(:)))/(max(ms(:)-min(ms(:));

And then writing as tiff, jpeg, whatever, e.g.

imwrite(uint8(msc),'outputFile.tif');

For quantitative EM work you'd probably want to write it out as an MRC file,

pixA=1.33; % angstroms per pixel
WriteMRC(m,pixA,'MyFilename.mrc');

Shaf2016

Dear Dr.Sigworth

Zero numbers are for zero intensities? I want to obtain the total intensity of detector map.

Shaf2016

Dear Dr.Sigworth

Thank you. I used the function to read dm3 file. It gave many numbers. Is that correct? If I want to see the image, I have to convert dm3 to tiff?

Shaf2016

Yifei Meng

This is so far the best script to read a dm3/dm4 file. Users can easily modify the code to extract useful tag information.

If you are still using the 32-bit MatLab, the script might not work. Simply change uint(64) to uint(32) at line 67, 193 and 357.

Yifei Meng

The code is great since it reads DM3 image stacks as well as the tag structure!
I would like to extract additional information from the DM3 tags. I was able to extract one additional tag by modifying the code, but found that a second tag which I would like to extract was not possible because several of the fields to which it belongs have spaces in their names, (e.g. "Indicated Magnification"). Is there a simple way to get around this limitation?

Dear Soum,
I'm sorry, I didn't see your comment till now.
filename is a string containing the full filename including path. logfile is a string containing the full filename of an ascii log file in case you want one.
Here's an example of using the function. Say I want to read the file whose full pathname is /Users/fred/EMData/img.dm4
I could for example do this
cd('/Users/fred/EMData')
m=ReadDMFile('img.dm4');
or this
m=ReadDMFile('/Users/fred/EMData/img.dm4');
If you have further troubles you can also email me at fred.sigworth@yale.edu

Soum

Soum

Hi Mr.Fred Sigworth;

I'm trying to read my .DM3 file but what do you mean by filename and logfile
is filename:the path of my data and log file its name?
I'm waiting for your answer thank you in advance

Updates

1.1.0.0

Updated to remove a bug that caused an error on reading some .dm3 files.

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Imagic, MRC, DM and STAR file i/o

Inspired: DiffractIndex