Skip to main content
. Author manuscript; available in PMC: 2026 Jun 8.
Published in final edited form as: Methods. 2025 Jul 28;242:113–122. doi: 10.1016/j.ymeth.2025.07.007

Algorithm 4.

Inferring 3D segmentation of cell nuclei

Require: C3D_final: 3D array of final 3D cell regions with unique indices from Algorithm 3
Require: N2D: 3D array of 2D nuclear regions from the Z-axis, each uniquely indexed at its Z-slice
1: N3D_final ← empty 3D array for final 3D nuclear regions
2: final_indices ← list of unique indices of 3D cell regions in C3D_final
3: for index in final_indices do
4: {Iterate over each final 3D cell region}
5:  for z in unique(where(C3D_final[z,:,:]==index)) do
6:   {Iterate over the Z-slices where the current 3D cell region exists}
7:   2D_region_coords ← where(C3D_final[z,:,:]==index)
8:   C2D⟵empty 2D array with the same XY dimensions as C3D_final{Initialize array for individual final 3D cell region at slice z }
9:   N2D⟵ empty 2D array with the same XY dimensions as C3D_final{Initialize array for individual final 3D nuclear region at slice z}
10:    C2D [2D_region_coords] ← index {2D array with index value at the coordinates of current final 3D cell region at slice z}
11:    N2D[2D_region_coords] ← N2D[z, 2D_region_coords] {2D array with indexed 2D nuclear regions overlapping with C2D}
12:    if num(unique(N2D))> 1 then
13:     {If more than one nucleus is present}
14:     N2D ⟵selectNucleus(N2D,C2D)
15:     {Keep the nucleus with the smallest fraction beyond and on cell boundaries}
16:    end if
17:    N2D⟵trimNucleus(N2D,C2D)
18:    {Remove nuclear pixels outside or on cell boundaries}
19:    N3D_final[z,where(N2D≠0)] ← index
20:    {Store the trimmed 2D nuclear region}
21:  end for
22: end for
23: for index in final_indices do
24:  3D_region_coords ⟵ where (C3D_final==index)
25:  {Get the 3D coordinates of the current final 3D cell region}
26:  num_overlap ⟵ findNucleus(3D_region_coords, N3D_final)
27:  {Find the number of overlapping 3D nuclear regions}
28:  if num overlap = = 0 then
29:   C3D_final[3D_region_coords] ← 0
30:   {Remove final 3D cell regions that do not have corresponding 3D nuclear region}
31:  end if
32: end for