SegmentSeeded1.0Segments a directory of images with various methods, using a seed (a previous mask helping in refining the segmentation).
The method choices are:

Otsu's method thresholds the object intensities so that the intra-class variance is maximized. The calculated threshold value can be multiplied with a correction constant, to improve the result.

Shape method thresholds the objects at several intensity levels and searches for objects fitting the size and roundness criteria given in the parameters.

ConstantArea method thresholds the objects at several intensity levels and returns a mask where a certain ratio of object area is included in the mask. Filling/size restrictions are applied after masking. Use constant to control the area ratio.
A minimization function is used, so the area fraction may not be accurate.

KNN method takes a CSV file with cluster numbers and color values, and seeks the nearest neighbor for each pixel.

kernel method takes a CSV file with cluster numbers and color values, and seeks the nearest neighbor for each pixel by using any metric provided in the 'kernel' parameter. NOTE: Since custom metric is used, the full distance matrix from each pixel to color value is calculated. It easily consumes a lot of memory if either is large.

quadratic method takes a CSV file with cluster numbers and color values, and uses a quadratic classifer to get pixel classes.

All the methods work on per-object basis.
Ville RantanenImage ProcessingMatlabA directory with grayscale image files. (or possibly RGB for 'KNN')Directory of mask files that restrict the pixels used for segmentation.CSV file with 2 or 4 columns. First with cluster number, and other(s) with color values (range 0-1), order R G B.Method for image segmentation. Choose from 'Otsu', 'Shape', 'ConstantArea','KNN','Kernel','Quadratic'.Fill holes in segmented objects. Applicable to all methods.Clear objects touching the image edges. Applicable to all methods.The area ratio in ConstantArea method.Correction multiplier for threshold value in 'Otsu' method.Minimum accepted pixel area in all methods.Maximum accepted pixel area in all methods. Use 0 for no limit.Minimum accepted intensity value in 'Shape' and 'Otsu' methods. Ranges 0-1.Minimum accepted roundness value in 'Shape' method.Maximum accepted roundness value in 'Shape' method.Minimum accepted eccentricity value in 'Shape' method.Maximum accepted eccentricity value in 'Shape' method.Draw images of the numbers of the objects in the mask. This can be a lengthy process if there are huge amounts of objects.Kernel in 'kernel' method. Cluster will be chosen by maximizing the kernel value. The 'x' is the vector of distances for the colors in the cluster.