두 패스 연결 구성 알고리즘은 하나의 이미지에서 별도의 구성 요소를 감지하고 각 감지 후에는 component
을 다른 이미지로 저장합니다. 모든 component
을 별도의 이미지에 표시하려면 여러 개의 if 조건을 사용하고 있지만 각 구성 요소의 이미지에 많은 모양이있을 때마다이 if conditions
이 증가하고 있습니다. 지금까지는 조건이 7 개 있지만 증분을 사용했습니다. 어떤 아이디어가 그것을 위해 루프를 사용하는 방법이나 그것을 다루는 방법.두 패스 연결 구성 요소, 구성 요소 수 문제
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')
[코드가 여러 개인 경우 루프를 사용하는 방법] (https://stackoverflow.com/questions/47969274/how-to-use-loop-for-multiple-if-coniditions) –