0

肺の純粋なバイナリ マスクを作成するのに苦労しているという問題があります。ピクセル値は肺の内側にあり、肺の外側は 1 です。kmeans と otsu およびその他のいくつかの方法を使用して、肺をセグメント化しました。いくつかの例の写真を添付し​​ます。

最初の例

2 番目の例、同じ患者/CT。なぜこれが円で囲まれているのかわかりません

これは、3D numpy 配列へのリンクです。それはすべてのスライスなので、おそらく1つのスライスを試してみたいと思うでしょう.

https://drive.google.com/file/d/1nktGBYZGz1iJDR_-yarzlRs-c4xOp__9/view?usp=sharing

ご覧のとおり、肺はうまく分割されています。(写真真ん中の白です。)その真ん中の白い塊(肺)を特定し、その外側のすべてのピクセルを黒(0?)にする方法はありますか?

肺をセグメント化するために使用したコードを次に示します (バイナリ マスクを作成します)。

def HUValueSegmentation(image, fill_lung_structures=True):

# not actually binary, but 1 and 2. 
# 0 is treated as background, which we do not want
binary_image = np.array(image > -320, dtype=np.int8)+1
labels = measure.label(binary_image)

# Pick the pixel in the very corner to determine which label is air.
#   Improvement: Pick multiple background labels from around the patient
#   More resistant to "trays" on which the patient lays cutting the air 
#   around the person in half
background_label = labels[0,0,0]

#Fill the air around the person
binary_image[background_label == labels] = 2


# Method of filling the lung structures (that is superior to something like 
# morphological closing)
if fill_lung_structures:
    # For every slice we determine the largest solid structure
    for i, axial_slice in enumerate(binary_image):
        axial_slice = axial_slice - 1
        labeling = measure.label(axial_slice)
        l_max = largest_label_volume(labeling, bg=0)
        
        if l_max is not None: #This slice contains some lung
            binary_image[i][labeling != l_max] = 1


binary_image -= 1 #Make the image actual binary
binary_image = 1-binary_image # Invert it, lungs are now 1

# Remove other air pockets insided body
labels = measure.label(binary_image, background=0)
l_max = largest_label_volume(labels, bg=0)
if l_max is not None: # There are air pockets
    binary_image[labels != l_max] = 0

return binary_image
4

1 に答える 1