.mat file from ConvertObjectsToImage: datatype

I am using ConvertObjectsToImage, color type uint16 and then saving the result as a .mat file using SaveImages.

Sometimes, the mat file is 4X larger than the others. When I load it in matlab, the datatype of the matlab variable Image is double. For the smaller mat files (from the same run), the datatype of the matlab variable Image is int16.

When I run unique(Image) in matlab, it confirms that in both cases, there are less than 500 labels in each mat file. Why is the datatype in some cases double and in other cases int16?

Hi,

I suspect that the issue is the number of labels in each particular image. If there are >255, then SaveImages:

Therefore, saved image files that have <256 labels will use significantly less disk space than those with >255 labels.
Let us know if that makes sense for your files. If not, feel free to post an example of small and large .mat files and we’ll take a look.

Side note: I’m not certain it will help you, but note that SaveImages can save Objects directly – see the first setting in that module. You may be able to skip the ConvertObjectsToImage altogether.

David

Hi David,

Actually, it doesn’t quite make sense. I just did a run where I cropped the images. In one case, there are 148 objects and the mat file is 2,439 kb. When that mat file is loaded in matlab, the data type of the variable Image is int16, which is good.

In the other case, there are 42 objects (i.e. fewer than before) and the mat file is 9,753 kb. When this mat file is loaded in matlab, the data type of the variable Image is double (which explains why the mat file size it is now 4X larger).

In the original uncropped images, where I have many more objects (more than 256), sometimes the mat file is 1X size and datatype int16 and sometimes the mat file is 4X size and datatype double.

My concern is that the datatype of the Image variable saved in the mat file should never be double, since the object labels are always integers. It should either be int16 or int8.

I also see this problem whether I first use ConvertObjectsToImage or use SaveImages directly, as you suggested.

It is not a major problem, but it is a little strange and I end up (in my original uncropped images) with unnecessarily large (150 MB) mat files.

I hesitate to upload 10MB mat files… should I?

This does sound strange. Yes, please try posting the .mat files as well as the pipeline. You can also use your own Dropbox or Google Drive to host the files, if size or filetype is an issue, and then post the link here.

David