def eval_baseline_on_photo(pixel_labels_dir, thres_list, photo_id,
pred_shading_dir, bl_filter_size):
"""
This method generates a list of precision-recall pairs and confusion
matrices for each threshold provided in ``thres_list`` for a specific
photo.
:param pixel_labels_dir: Directory which contains the SAW pixel labels for each photo.
:param thres_list: List of shading gradient magnitude thresholds we use to
generate points on the precision-recall curve.
:param photo_id: ID of the photo we want to evaluate on.
:param pred_shading_dir: Directory which contains the intrinsic image
decompositions for all photos generated by a decomposition algorithm.
:param bl_filter_size: The size of the maximum filter used on the shading
gradient magnitude image. We used 10 in the paper. If 0, we do not filter.
"""
shading_image_arr = load_shading_image_arr(
pred_shading_dir=pred_shading_dir, photo_id=photo_id
)
shading_image_linear = srgb_to_rgb(shading_image_arr)
shading_image_linear_grayscale = np.mean(shading_image_linear, axis=2)
shading_gradmag = compute_gradmag(shading_image_linear_grayscale)
if bl_filter_size:
shading_gradmag = maximum_filter(shading_gradmag, size=bl_filter_size)
# We have the following ground truth labels:
# (0) normal/depth discontinuity non-smooth shading (NS-ND)
# (1) shadow boundary non-smooth shading (NS-SB)
# (2) smooth shading (S)
# (100) no data, ignored
y_true = load_pixel_labels(pixel_labels_dir=pixel_labels_dir, photo_id=photo_id)
y_true = np.ravel(y_true)
ignored_mask = y_true == 100
# If we don't have labels for this photo (so everything is ignored), return
# None
if np.all(ignored_mask):
return [None] * len(thres_list)
ret = []
for thres in thres_list:
y_pred = (shading_gradmag < thres).astype(int)
y_pred = np.ravel(y_pred)
# Note: y_pred should have the same image resolution as y_true
assert y_pred.shape == y_true.shape
ret.append(grouped_confusion_matrix(y_true[~ignored_mask], y_pred[~ignored_mask]))
return ret
评论列表
文章目录