File Exchange

image thumbnail

Read .dm3 and .dm4 image files

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


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"

Cite As

Fred Sigworth (2020). Read .dm3 and .dm4 image files (, MATLAB Central File Exchange. Retrieved .

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.

colormap gray % set up a grayscale display

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


then draw a 1000-bin histogram of all pixels,

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:


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


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

pixA=1.33; % angstroms per pixel


Dear Dr.Sigworth

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


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?


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
or this
If you have further troubles you can also email me at



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


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

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

Inspired: DiffractIndex