home > kero > Documentation

kero.ImageProcessing.photoBox.py def find_first_non_zero_index(mat, row_start=0): return i, j

mat | 2D matrix. List of list or numpy array |

row_start | Integer. The value row_start is the index of the row from which this function will start looking for the first non-zero element. This means the function will start searching from the (row_start + 1) row of the matrix.
Default to zero, i.e. start searching from the first row. |

Return i, j | The index (i, j) where the matrix has non-zero element, starting from row (row_start)-th index. |

**Example Usage 1**

import kero.ImageProcessing.photoBox as kip import numpy as np # gs_matrix = [ # [1,1,0,0,1 ], # [1,0,0,1,1 ], # [1,1,1,0,1 ] # ] gs_matrix = np.random.randint(2, size=(5, 10)) print(gs_matrix) this_i, this_j = kip.find_first_non_zero_index(gs_matrix) print("first non zero index: ", this_i, this_j) start_entry = [this_i, this_j] [row_index, column_index_list, out_mat, liber_mat] = kip.find_segment_index(gs_matrix, start_entry) print("first segment index: ", row_index, " : ", column_index_list)

The output:

[[11 0 1 1 1 0 1 1 0] [0 1 1 1 1 1 1 0 1 1] [0 0 1 1 0 0 1 1 1 1] [0 0 1 0 1 0 1 0 0 0] [1 1 0 0 0 1 0 1 0 1]]first non zero index: 0 0first segment index: 0 : [0, 1]

The first non zero index is bolded in blue.

*kero version: 0.4 and above*