MatLab can be a useful tool for image processing, but it can be useful to then take the results back into the Digital Micrographs DM) software from Gatan. Let’s use a landscape crop of the Lenna image with different height and width to demonstrate how to do this. This is what the variable looks like inside MatLab:

We start by plotting the result inside MatLab, in greyscale with the axis ticks hidden:

```
imagesc(Lenna_landscape)
axis image
colormap gray
set(gca,'xtick',[],'ytick',[])
```

This is the result:

Next, we will write this data to a binary file (*.bin) that is compatible with DM. The code to do this depends on the type of computer you have, 32 or 64 bit:

```
computer_type = computer ;
if strcmp(computer_type,'PCWIN') == 1
fid = fopen('Lenna_binary.bin','w');
fwrite(fid, Lenna_landscape , '*float32', 'l');
fclose(fid);
elseif strcmp(computer_type,'PCWIN64') == 1
fid = fopen('Lenna_binary.bin','w');
fwrite(fid, Lenna_landscape , '*float32', 'a');
fclose(fid);
end
```

This will write to the current folder a file ‘Lenna_binary.bin’. Then from within DM, go to File > Import and select this file. You may need to click to show ‘All Files’ in the import window to be able to see the *.bin file. In the dialogue box that opens you will need to select the format to ‘Binary’ and the data type to ‘Real 4 Byte’ to match the file we wrote earlier. Next enter the width and height that matches the dimensions shown in the MatLab workspace. The ‘width’ should equal the first MatLab dimension. This yields the following:

## Fixing the Transpose Problem

The result above has the Lenna image mirrored and rotated by 90°. This comes from the way MatLab treats data as ‘row-preference’, whereas DM, is ‘column-wise’. To fix this we simply transpose the data before writing the *.bin file. This is easy and just requires one extra character in the code:

```
computer_type = computer ;
if strcmp(computer_type,'PCWIN') == 1
fid = fopen('Lenna_binary.bin','w');
fwrite(fid, Lenna_landscape' , '*float32', 'l');
fclose(fid);
elseif strcmp(computer_type,'PCWIN64') == 1
fid = fopen('Lenna_binary.bin','w');
fwrite(fid, Lenna_landscape' , '*float32', 'a');
fclose(fid);
end
```

Next we can import this to DM just as before, but importantly we must also change the width and height dimensions around. Nothing else needs to be changed.

Now the results match the MatLab view as expected.

## Importing 3D Data (stacks / series)

If the MatLab variable is a stack or image-series, then the procedure is exactly the same, only you must also specify the ‘Depth’ of the data during import. This must match the number of frames – i.e. the third dimension in MatLab.

Is it possible to show the EELS reference ?