Skip to content

Commit

Permalink
Add external postprocessing with grayscale option to config
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanklut committed Feb 21, 2024
1 parent 20ae3eb commit 9b87e52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 7 additions & 0 deletions configs/extra_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@
_C.INPUT.ORIENTATION.PERCENTAGES = [1.0, 0.0, 0.0, 0.0]


# Postprocessing
_C.POSTPROCESS = CN()
_C.POSTPROCESS.EXTERNAL = CN()
_C.POSTPROCESS.EXTERNAL.ENABLED = True
_C.POSTPROCESS.EXTERNAL.GRAYSCALE = True


# Solver
_C.SOLVER = CN()
# weight decay on embedding
Expand Down
14 changes: 4 additions & 10 deletions page_xml/baseline_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def most_likely_orientation(overlap_image: np.ndarray, top_image: np.ndarray, bo
rotated_top_image,
rotated_bottom_image,
rotation_matrix,
((max_dimension + h) / 2, (max_dimension + w) / 2),
(max_dimension - w // 2, max_dimension - h // 2),
)

return output
Expand Down Expand Up @@ -367,20 +367,14 @@ def top_bottom_converter(
top_bottom_overlap_sub_image,
top_sub_image,
bottom_sub_image,
15,
45,
)

if best_orientation is None:
raise ValueError("No best orientation found")

rotated_overlap_image, rotated_top_image, rotated_bottom_image, rotation_matrix, offset = best_orientation

print("BEST ORIENTATION", rotation_matrix)
import matplotlib.pyplot as plt

plt.imshow(labels_overlap == i, cmap="gray")
plt.show()

baseline = extract_baseline_v2(rotated_overlap_image, "test.xml", (0, 0), 1, step)
if len(baseline) < 2:
continue
Expand All @@ -390,11 +384,11 @@ def top_bottom_converter(
continue

inv_rotation_matrix = np.eye(3)
inv_rotation_matrix[:2, :2] = rotation_matrix[:2, :2]
inv_rotation_matrix[:2] = rotation_matrix
inv_rotation_matrix = np.linalg.inv(inv_rotation_matrix)

baseline = cv2.transform(baseline[:, None, :], inv_rotation_matrix)[:, 0, :2]
baseline += np.asarray([x_offset_overlap, y_offset_overlap]) - offset
baseline += np.asarray([rectangle_combined[0], rectangle_combined[1]]) - offset

baselines.append(baseline)

Expand Down
2 changes: 2 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ def main(args: argparse.Namespace) -> None:
whitelist=args.whitelist,
rectangle_regions=cfg.PREPROCESS.REGION.RECTANGLE_REGIONS,
min_region_size=cfg.PREPROCESS.REGION.MIN_REGION_SIZE,
external_processing=cfg.POSTPROCESS.EXTERNAL.ENABLED,
grayscale=cfg.POSTPROCESS.EXTERNAL.GRAYSCALE,
)

predictor = SavePredictor(
Expand Down

0 comments on commit 9b87e52

Please sign in to comment.