You should be able to do whatever the app does programmatically. The functions are listed here: https://www.mathworks.com/help/images/image-segmentation.html
To use the app within a function, you can use the "waitfor" command after calling the imageSegmenter App. https://www.mathworks.com/help/matlab/ref/waitfor.html
The imageSegmenter puts the variables (e.g. BW) into the base workspace, however. You could do something like evalin('base', 'BW') after using the imageSegmenter, within the function.