lundi 25 décembre 2017

How to use loop for multiple if coniditions

labels[(x, y)] return a value on coordinate(x) and coordinate(y).
labels[(x, y)] value is actually representing a different shapes in image and after detection each shape is being saved as a different image. for every shape or component i am using multiple if condition for example if labels[(x, y)]==0: SAVE IT AS DIFFERENT IMAGE but number is increasing whenever there are more shapes in an image. so far i have used 7 if conditions. how can i solve this problem by only one if condition.

for (x, y) in labels:
                component = uf.find(labels[(x, y)])
                labels[(x, y)] = component
                print (format(x) +","+ format(y)+ " " +format(labels[(x, y)]))
                ###################
                if labels[(x, y)]==0:
                    Zero[y][x]=int(255)
                    count=count+1
                    if count<=43:
                        continue
                    elif count>43:
                        Zeroth = Image.fromarray(Zero)
                        Zeroth.save(os.path.join(dirs, 'Zero.png'), 'png')
                #############
                if labels[(x, y)]==1:
                    One[y][x]=int(255)
                    count1=count1+1
                    if count1<=43:
                        continue
                    elif count1>43:
                        First = Image.fromarray(One)
                        First.save(os.path.join(dirs, 'First.png'),'png')

    irs, 'First.png'),'png')

Aucun commentaire:

Enregistrer un commentaire