How to use the splitted sub array of an array after using array.split() method in python? -
- I want to convert my image to a numpy array
- and then this array Two arrays (so that the left half of the image is the right half for one array and the other)
- I want to count the zero zero elements of these two arrays and compare them with each other and Boolean output
Can not I understand how to use these two arrays so that I can count
zero elements of each array < / P> This is my code so far:
Import import from PIL import as npi np image = Image.open ('myimage.jpg') array = np.array (Image) split = np.split (array, 2,0) // The code is working fine as long as you use
np.split (array, 2, this point < / pre>
you set it in two arrays Es, so you will take part in the upper half and lower half. You want to divide the left and right side axis with1 :
np.split (array, 2, 1) .
Second,
np.split returns two if you are divided into two, and they are stored in a list if you want one first Use
split [0] and if you want the second, use
split [1] , or if you want to open them at once:
left, right = np.split (array, 2, 1)
Now, to calculate the elements of the ngereo, define "element" Be careful, because more carefully, because There are three elements per pixel in the JPG image if you want the element, then just use:
lcount = np.count_nonzero (left)
if If you want a pixel, you have to convert to grayscale in some way Here's a way:
Gray = NP Larry (im.convert ('l')) lgray, rgray = np.split (gray, 2, 1) lcount = np.count_nonzero (lgrey)
I also started a small Because you do not want to use the
Image because it's already module name
PIL :
import from PIL import Import NPI as np im = Image.open ('myimage.jpg') # There is no name, module image is there. arr = np.array (im) left, right = np.split (arr, 2, 1)
Comments
Post a Comment