How to load label matrices with multiple object numbers

Hi all,

First-time asker, long-time answerer… :wink:

I thought loading label matrices with multiple object numbers was possible, but I can’t get it to read in the individual labels, and so maybe I need a new perspective! My use-case is loading saved ilastik segmentations (not probability maps) into CP. A user can load these label matrices with NamesAndTypes set to “Objects”, however there seems to be no way to access labels 1 vs. 2 or higher – they just load as a single object for the entire label matrix. Is this possible and I’m just blanking, or should I make a Github issue?


Answer from a long-time asker, short-time answerer-

There is implementation for this as part of the Train mode in the Classify module of the pixelclassifier branch, but it seems to just be multiplying the scale of the image times the greyscale value in order to create classes. AFAIK that’s the only way to do it but I haven’t worked with any of the classification modules much.

The hacky-workaround way to do it would probably be to load the labels matrix as a greyscale image then iteratively threshold and mask out the different classes- ie if you had 3 classes+background, do a rescale and then ApplyThreshold (0.75), MaskImages on the label matrix with the mask reversed, ApplyThreshold (0.50) on the masked image from round 1, MaskImages again, ApplyThreshold 0.25 . You’d then have a mask for each of your 3 sets of labels, which you could apply to the actual images of interest to segment objects and do all your fun stuff.

That being said, it probably is worth having a nice way to do it so if you make a GitHub issue I’ll support you. :smile:

You mean a pipeline that looks like this? :grinning: That’s exactly what I did:

This works (though the last class with pixel intensity = 0 necessitated another workaround, i.e. invert), but it’s ugly. Glad to hear that I wasn’t missing something obvious. I’ll add a new Github issue, thanks!

1 Like