交並比(Intersection over Union)
另一種成本函式是交並比(IOU, Intersection over Union)。IOU 是兩張影像中同時為填滿像素的數量(「交集」)除以任一張影像為填滿像素的數量(「並集」)。
在這個練習中,請決定如何轉換 im1,才能讓與 im2 的 IOU 成本函式達到「最大化」。我們已經為你定義好以下函式:
def intersection_of_union(im1, im2):
i = np.logical_and(im1, im2)
u = np.logical_or(im1, im2)
return i.sum() / u.sum()
注意:使用 ndi.rotate() 時,記得加入 reshape=False,以確保陣列形狀相同。
本練習屬於課程
