# get_segment_set()

This function deconstruct a matrix of zeros and ones to a list of its rows. And then, each row is deconstructed to its segments.

```kero.ImageProcessing.photoBox.py

def get_segment_set(mat):
return liber_mat_set, segment_set```

 mat 2D matrix. List of list or numpy array return liber_mat_set List of 2D matrix. Each matrix is a zero matrix, except it contains a segment from some row. return segment_set List (3 level). It is a collection of list (a matrix row) of segments.

Example usage 1

```import kero.ImageProcessing.photoBox as kip
import numpy as np

# gs_matrix = np.random.randint(2, size=(5, 10))
gs_matrix=[[0,1,1,0,0],[1,0,0,0,1],[1,1,1,1,1]]

print("gs_matrix:\n")
for x in gs_matrix:
print(x)

liber_mat_set, segment_set = kip.get_segment_set(gs_matrix)

print("\n**** liber mat view: ****")
seg = [*len(gs_matrix) for i in range(len(gs_matrix))]
for k in range(len(liber_mat_set)):
print("---- k = ", k , " ----")
for i in range(len(liber_mat_set[k])):
print(liber_mat_set[k][i])

print("\nmatrix reconstructed from sum of segments. They should be equal to gs_matrix")
for k in seg:
print(k)

print("\n**** segment view: ****")
for k in range(len(segment_set)):
print("---- k = ", k , " ----")
for i in range(len(segment_set[k])):
print(segment_set[k][i])```

The output is shown below.

```gs_matrix:

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

**** liber mat view: ****
---- k = 0 ----
[[0, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
---- k = 1 ----
[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]
---- k = 2 ----
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]

matrix reconstructed from sum of segments. They should be equal to gs_matrix
[0, 1, 1, 0, 0]
[1, 0, 0, 0, 1]
[1, 1, 1, 1, 1]

**** segment view: ****
---- k = 0 ----
[0, 1, 1, 0, 0]
---- k = 1 ----
[1, 0, 0, 0, 0]
[0, 0, 0, 0, 1]
---- k = 2 ----
[1, 1, 1, 1, 1]```

kero version: 0.4 and above