In this article, you can read about how to generate complete object masks, also known as (semantic) segmentation masks.
The image below shows an example of a complete object mask. White pixels in the object mask represent the objects and black pixels represent the background. It is also okay for the images to show more then one object. As long as we have only two classes (objects and background), we speak of binary segmentation.
It we however have more than two classes, then we speak about semantic segmentation. In this case, using black (0) and white (1) does not suffice but and we have to introduce a third color. In the image below this color is gray (0.5).
Generating complete object masks
There are plenty of methods to generate complete object masks. The most reliable, but also most laborious method is to mark the objects by hand. Fortunately, there exist several automatic methods, such as k-means clustering and Otsu’s threshold. Click here for a complete overview of all methods MATLAB has to offer for image segmentation. Most of these methods are also implemented in various Python packages, such as skimage. Also ImageJ offers multiple methods for image segmentation natively as well as with the help of plugins.
Storing complete object masks
It is best, to always store a complete object mask along with the original image it is based on. Every image has exactly one complete object mask and each color of an object mask represents a class of objects of your dataset. It is very important that each class within a dataset is always represented by the same color within the dataset.
If you found this How-To useful, then be sure to check out our other How-Tos.