dimanche 24 décembre 2017

Two pass connected component, Number of components issue

Two pass connected component algorithm is detecting separate components in one image, and after each detection i am saving every component as a different image. To display every component on separate image i am using multiple if conditions but these if conditions are increasing whenever there are alot of shapes in an image for every component, so far i have used 7 if conditions but it is increaing. Any ideas how to use loop for it or how to deal with it.

 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<=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')

Aucun commentaire:

Enregistrer un commentaire