If there are 256 or fewer regions, then this can be accomplished using an indexed colour duplicate of the image to define the matte regions.
Here's a script which attempts to automate this on the current document:
#target photoshop
var ChannelIDs = {
RED: "Rd ",
GREEN: "Grn ",
BLUE: "Bl ",
RGB: "RGB "
};
function isSelectionEmpty(doc) {
try {
return (doc.selection.bounds) ? false : true;
} catch (err) {
return true;
}
}
function createChannelFromSelection(doc, channelName) {
var chan = doc.channels.add();
chan.name = channelName;
chan.kind = ChannelType.SELECTEDAREA;
doc.selection.store(chan, SelectionType.REPLACE);
}
function cutToLayer() { // "Layer via cut"
executeAction(charIDToTypeID("CtTL"), undefined, DialogModes.NO);
}
function createSnapshot(snapshotName) {
var makDescriptor = new ActionDescriptor(),
snapshotAction = new ActionReference(),
fromRef = new ActionReference();
snapshotAction.putClass(charIDToTypeID("SnpS"));
makDescriptor.putReference(charIDToTypeID("null"), snapshotAction);
fromRef.putProperty(charIDToTypeID("HstS"), charIDToTypeID("CrnH"));
makDescriptor.putReference(charIDToTypeID("From"), fromRef);
if (snapshotName) { // Assign snapshot name
makDescriptor.putString(charIDToTypeID("Nm "), snapshotName );
makDescriptor.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("HstS"), charIDToTypeID("FllD") );
}
executeAction(charIDToTypeID("Mk "), makDescriptor, DialogModes.NO);
}
function restoreSnapshot(snapshotName) {
if (!snapshotName) { throw new Error("Expected snapshot name"); }
var selectDescriptor = new ActionDescriptor(),
snapshotRef = new ActionReference();
snapshotRef.putName(charIDToTypeID("SnpS"), snapshotName);
selectDescriptor.putReference(charIDToTypeID("null"), snapshotRef);
executeAction(charIDToTypeID("slct"), selectDescriptor, DialogModes.NO);
}
function selectChannel(channelId) {
if (!channelId) { throw new Error("Expected channel ID"); }
var setDescriptor = new ActionDescriptor(),
selectRef = new ActionReference(),
channelRef = new ActionReference(),
idChnl = charIDToTypeID("Chnl");
selectRef.putProperty(idChnl, charIDToTypeID("fsel"));
setDescriptor.putReference(charIDToTypeID("null"), selectRef);
channelRef.putEnumerated(idChnl, idChnl, charIDToTypeID(channelId));
setDescriptor.putReference(charIDToTypeID("T "), channelRef);
executeAction(charIDToTypeID("setd"), setDescriptor, DialogModes.NO);
};
function loadSelection(docName, channelName) {
var setDescriptor = new ActionDescriptor(),
selectRef = new ActionReference(),
docRef = new ActionReference(),
idChnl = charIDToTypeID("Chnl");
selectRef.putProperty(idChnl, charIDToTypeID("fsel"));
setDescriptor.putReference(charIDToTypeID("null"), selectRef);
docRef.putName(idChnl, channelName);
docRef.putName(charIDToTypeID("Dcmn"), docName);
setDescriptor.putReference(charIDToTypeID("T "), docRef);
executeAction(charIDToTypeID("setd"), setDescriptor, DialogModes.NO);
}
function convertToIndexedColour(doc) {
var opts = new IndexedConversionOptions();
opts.dither = Dither.NONE;
opts.forced = ForcedColors.NONE;
opts.matte = MatteType.NONE;
opts.palette = Palette.EXACT;
opts.transparency = false;
doc.changeMode(ChangeMode.INDEXEDCOLOR, opts);
}
function selectColourTableEntry(i) {
var actionSet = charIDToTypeID("setd");
var setDescriptor = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Clr "), charIDToTypeID("ClrT"));
setDescriptor.putReference(charIDToTypeID("null"), ref);
var colourTable = new ActionList();
if (i > 0) { // Fill low part of colour table
for (var n = 0; n < i; ++n) {
addColourTableEntry(colourTable, 0, 0, 0);
}
}
// Select single entry
addColourTableEntry(colourTable, 255, 255, 255);
if (i < 255) { // Fill high part of colour table
for (var n = i + 1; n < 256; ++n) {
addColourTableEntry(colourTable, 0, 0, 0);
}
}
setDescriptor.putList(charIDToTypeID("T "), colourTable);
executeAction(actionSet, setDescriptor, DialogModes.NO);
}
function addColourTableEntry(colourTable, r, g, b) {
var entry = new ActionDescriptor();
entry.putDouble(charIDToTypeID(ChannelIDs.RED), r);
entry.putDouble(charIDToTypeID(ChannelIDs.GREEN), g);
entry.putDouble(charIDToTypeID(ChannelIDs.BLUE), b);
colourTable.putObject(charIDToTypeID("RGBC"), entry);
}
function main() {
var doc = activeDocument;
var lyr = doc.activeLayer;
// Create indexed duplicate
var dupDoc = doc.duplicate();
activeDocument = dupDoc;
convertToIndexedColour(dupDoc);
var snapshotName = "indexed";
var channelName = "matte";
var i;
// Snapshot the current history state
createSnapshot(snapshotName);
for (i = 0; i < 256; ++i) {
selectColourTableEntry(i);
// For some reason selecting channels doesn't work in indexed mode?
dupDoc.changeMode(ChangeMode.RGB);
// Create new matte from red channel
selectChannel(ChannelIDs.RED);
// If there is no selection then we're done
if (isSelectionEmpty(dupDoc)) { break; }
createChannelFromSelection(dupDoc, channelName);
// Use matte to cut new layer in original document
activeDocument = doc;
loadSelection(dupDoc.name, channelName);
cutToLayer();
doc.activeLayer.name = "Region " + (i + 1);
// Reset ready for next layer
doc.activeLayer = lyr;
activeDocument = dupDoc;
restoreSnapshot(snapshotName);
}
// Clean up
activeDocument = dupDoc;
dupDoc.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc;
doc.activeLayer.remove();
alert("Found " + i + " region" + (i === 1 ? "" : "s"));
}
main();
If there are more than 256 objects, then some will be merged when converting to indexed colour.
Tested in Photoshop CC