0

I have an image which has already been tiled and then segmented (outside my pipeline). Segmentation was carried out separately on each tile and I have the corresponding label_image arrays.

These are just arrays the same size as the tiles; The value of each element in the array corresponds to a real life object on the tile. Zero means background, 1 means that the first object etc. For example if we had an image with two objects, one diamond-shaped and one square on the top-left and bottom-right corner respectively, then the label_image array would look like this:

[0, 0, 0, 0, 0, 0, 0, 0,
 0, 1, 0, 0, 0, 0, 0, 0,
 1, 1, 1, 0, 0, 0, 0, 0,
 0, 1, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 2, 2, 2, 0,
 0, 0, 0, 0, 2, 2, 2, 0,
 0, 0, 0, 0, 2, 2, 2, 0,
 0, 0, 0, 0, 0, 0, 0, 0]

In my case, lets say the original image looks like the one shown below at the left but segmentation was done on each of the 4 smaller images shown below on the right with red outlines and I have the four label_image arrays.

enter image description here

How do I join these four smaller label_images to get one single label_image for the big image please?

An object (coin in this example) that sits on the boundaries will appear in two (at least) label_images in the end result however they should be expressed as one unified unclipped object, hence they should been given the same number.

Apart from the label_images I also have the centroids and everything else that comes from the regionprops function.

(image taken from here)

Aenaon
  • 3,169
  • 4
  • 32
  • 60
  • I'm not aware of a general-purpose function for this, though it would be very useful to write one in skimage. If you have "perfect" segmentation on each chunk, you can use this approach from distributed labeling in dask_image: https://github.com/jni/dask-image/blob/163323b124dd771b7e48ada6d0e42043f18fc7f3/dask_image/ndmeasure/__init__.py#L403-L459 https://github.com/dask/dask-image/pull/94 You need to ensure the segment numbers are unique to each block and that there is a 0-boundary between segments that you don't want to merge – Juan Feb 24 '20 at 01:16
  • Briefly, the approach is to build a graph of label values matched across boundaries, and then use connected components to remap values across chunk boundaries. – Juan Feb 24 '20 at 01:22
  • Thanks! Can I check this with you please (in case you see it anyway...) I am trying to look into this but I guess it is not included in `version 0.2` of `dask-image`. Distributed labelling is quite new I understand whereas `v0.2` is more than a year old. The best option I have now if I want to play with functions like `_label_adjacency_graph` is to build `dask-image` from the source please? – Aenaon Feb 25 '20 at 17:06
  • 1
    Coming back to this...I looks to me that the function `across_block_label_grouping` is the main working horse here. This function can be run as a standalone function...copy-paste on a notebook along with the necessary imports and runs ok. I need now to figure out how to use it in my context. – Aenaon Feb 25 '20 at 17:49

0 Answers0