我已經使用統一生成了一個合成語意影像分割資料集。我注意到我使用的著色器似乎在某些情況下沿邊界平均了我的類的像素值。比如下面第一張圖是unity生成的輸入X,第二張圖是我的unity生成的Y。問題是像素值是類之間的平均值。第三張圖片是一個掩碼,其中在掩碼值的關鍵集中沒有找到的白色值和灰度值在關鍵集中。
我總共有 6 個班級,所以它不像分配給一個班級那么簡單。我的問題是是否知道根據最近的有效鄰居填充這些值的有效方法?



這是我的相關代碼
ix = k.preprocessing.image.load_img(os.path.join(self.x_path,imgFile))
ix = k.preprocessing.image.img_to_array(ix)
iy = k.preprocessing.image.load_img(os.path.join(self.y_path,imgFile))
iy = k.preprocessing.image.img_to_array(iy)
#encode all of the RGB values to a class number
for mask_val, enc in self.dataSet.mask2class_encoding.items():
iy[np.all(iy==mask_val,axis=2)] = enc
#there were some that didnt encode and so I found that unity averages rgb values along class edge
foobarMask = None
for mask_val in self.dataSet.mask2class_encoding:
if foobarMask is None:
foobarMask = np.any(iy[:,:]!=mask_val,axis=2)
else:
foobarMask = np.logical_and(foobarMask,np.any(iy[:,:]!=mask_val,axis=2))
#mask2class_encoding{(255, 0, 0): 0, (45, 45, 45): 1, (255, 90, 0): 2, (0, 0, 255): 3, (111, 63, 12): 4, (255, 255, 0): 5}
現在我想基本上做一些基于掩碼的最近鄰插值,但我有點堅持如何做到這一點?任何幫助都非常感謝。如果有辦法一開始就阻止統一著色器這樣做,那就加分!
uj5u.com熱心網友回復:
事實證明這很簡單
indices = nd.distance_transform_edt(foobarMask, return_distances=False, return_indices=True)
iy = iy[tuple(indices)]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/428505.html
標籤:Python 麻木的 unity3d 深度学习 计算机视觉
上一篇:當int變數超過10位時
