How to make a condition that checks the binary image array and finds the zero row from the center?

210 Views Asked by At

Python: I want to make a condition that checks the binary image array and finds the zero rows from the center. if zero rows not available in the center then print the statement "Zero rows not available"...!

image:Image

Array= [[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255]
 [255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255]
 [255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255]
 [255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255   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   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   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   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   0   0   0   0   0   0]
[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255]
[255 255 255 255   0   0   0   0   0   0 255 255]]

What I have Tried:

img = np.array(img) 
moment = cv2.moments(img)   
X = int(moment ["m10"] / moment["m00"])
Y = int(moment ["m01"] / moment["m00"])
print(X,Y)
u = X ,Y
imagesE = cv2.findNonZero(u)
print(imagesE)

These are the Zero Rows. I want to find these zero rows from the center of an array through condition...!

[[
   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   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   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   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   0   0   0   0]]

Then I simply use the boolean operator "!" with cv2.findNonZero. But did not find require output.

1

There are 1 best solutions below

2
On

I have no idea what a "zero row from the centre" is, but you can get the sums of all the rows with:

rowSums = np.sum(array, axis=1)