# Morphological opening of volumetric DICOM images

I understand the concept of opening of 2D binary images but never used such opening on volumetric data as in the code below.

```nhood = ones([3 3 3]);
bw = imopen(bw,nhood); % bw is binary volumetric MRI data (28 slices)
```

If I create a structure element of ones([3 3]), this means it has three rows and three columns, but in the code above it is ones([3 3 3]). First 3 is for number of rows, the second for number of columns, but what is the remaining 3?

You have to think about volumes instead of images. You can call the third dimension and slices, and plot each of the slices:

```bw = imopen(bw,nhood);
[nRows, nCols, nSlics] = size(bw);
disp(['There are ', num2str(nSlics), 'with dimensions ', num2str(nRows), ' x ', num2str(nCols)])

for ii=1:nSlics
figure();
imshow(squeeze(bw(:,:,ii)));
title(['Slice ', num2str(ii), '/', num2str(nSlics)]);
end
```

When working in 3D, you want your structuring element be a 3D cube (containing 3*3*3=27 voxels) within your 3D volume: