lundi 22 janvier 2018

If conditions for unknown range of number

My code returns an image for every number .e.g if x==0 then it will create an image and save it in a particular folder but the issue is numbers are from 0 to lets say up to infinity how do i avoid multiple if conditions in such problem. Please ask if question is not clear. Here i posted only two if condition but it is increasing.

Zero=np.zeros(shape=(100, 100),dtype=np.uint8)  
count=0
count1=0
for (x, y) in labels:
        component = uf.find(labels[(x, y)])
        labels[(x, y)] = component
        if labels[(x, y)]==0:
            Zero[y][x]=int(255)
            count=count+1
            if count<=32:
                continue
            elif count>32:
                Zeroth = Image.fromarray(Zero)
                Zeroth.save(os.path.join(dirs, file_+'_Zero.png'), 'png')
        if labels[(x, y)]==1:
            One[y][x]=int(255)
            count1=count1+1
            if count1<=32:
                continue
            elif count1>32:
                First = Image.fromarray(One)
                First.save(os.path.join(dirs, file_+'_First.png'),'png')

Aucun commentaire:

Enregistrer un commentaire