(img, base_size, factor)
| 1068 | |
| 1069 | # Generating local patches to perform the local refinement described in section 6 of the main paper. |
| 1070 | def generatepatchs(img, base_size, factor): |
| 1071 | # Compute the gradients as a proxy of the contextual cues. |
| 1072 | img_gray = rgb2gray(img) |
| 1073 | whole_grad = np.abs(cv2.Sobel(img_gray, cv2.CV_64F, 0, 1, ksize=3)) + \ |
| 1074 | np.abs(cv2.Sobel(img_gray, cv2.CV_64F, 1, 0, ksize=3)) |
| 1075 | |
| 1076 | threshold = whole_grad[whole_grad > 0].mean() |
| 1077 | whole_grad[whole_grad < threshold] = 0 |
| 1078 | |
| 1079 | # We use the integral image to speed-up the evaluation of the amount of gradients for each patch. |
| 1080 | gf = whole_grad.sum() / len(whole_grad.reshape(-1)) |
| 1081 | grad_integral_image = cv2.integral(whole_grad) |
| 1082 | |
| 1083 | # Variables are selected such that the initial patch size would be the receptive field size |
| 1084 | # and the stride is set to 1/3 of the receptive field size. |
| 1085 | blsize = int(round(base_size / 2)) |
| 1086 | stride = int(round(blsize * 0.75)) |
| 1087 | |
| 1088 | # Get initial Grid |
| 1089 | patch_bound_list = applyGridpatch(blsize, stride, img, [0, 0, 0, 0]) |
| 1090 | |
| 1091 | # Refine initial Grid of patches by discarding the flat (in terms of gradients of the rgb image) ones. Refine |
| 1092 | # each patch size to ensure that there will be enough depth cues for the network to generate a consistent depth map. |
| 1093 | print("Selecting patches ...") |
| 1094 | patch_bound_list = adaptiveselection(grad_integral_image, patch_bound_list, gf, factor) |
| 1095 | |
| 1096 | # Sort the patch list to make sure the merging operation will be done with the correct order: starting from biggest |
| 1097 | # patch |
| 1098 | patchset = sorted(patch_bound_list.items(), key=lambda x: getitem(x[1], 'size'), reverse=True) |
| 1099 | return patchset |
| 1100 | |
| 1101 | |
| 1102 | def applyGridpatch(blsize, stride, img, box): |
no test coverage detected