Skip to content

Commit

Permalink
remove-grid is user option now
Browse files Browse the repository at this point in the history
  • Loading branch information
dilawar committed Jul 26, 2024
1 parent 843632b commit b501375
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion issues/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ issue_9: ./9-transparent-image/151915768-7d6fca3b-8967-4a0b-a1b9-a1815ad5aa3a.jp
cd .. && poetry install
poetry run plotdigitizer \
-p 0,0 -p 80,0 -p 0,800 \
$<
$< --debug
8 changes: 6 additions & 2 deletions plotdigitizer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def __init__(self, path: Path, coordinates: T.List[str], indices: T.List[str]):
self.orignal = cv.imread(self.path)
self.imgs = [("orig-gray-normalized", normalize(cv.imread(self.path, 0)))]

def remove_grid(self):
self._append("remove-grid", grid.remove_grid(self._last()))
def remove_grid(self, debug: bool):
image_with_grid = grid.remove_grid(self._last())
self._append("remove-grid", image_with_grid)
if debug:
plot.plot_images(self.imgs[-2::])

save_img_in_cache(self._last(), Path(f"{self.path.name}.without_grid.png"))
self._append("normalize", normalize(self._last()))
img = self._last()
Expand Down
16 changes: 15 additions & 1 deletion plotdigitizer/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@ def show_frame(img, msg="MSG: "):
cv.imshow(common.WindowName_, newImg)


def plot_images(images_with_title):
import matplotlib.pyplot as plt

total_images = len(images_with_title)
num_cols = 2
num_rows = min(1, total_images // num_cols)
for i, (title, img) in enumerate(images_with_title):
logger.debug(f"Plotting `{title}` as index {i+1}")
plt.subplot(num_rows, num_cols, i+1)
plt.imshow(img, interpolation="none")
plt.axis(False)
plt.title(title)
plt.show()


def plot_traj(traj, img, outfile: T.Optional[Path] = None):
global locations_
import matplotlib.pyplot as plt

x, y = zip(*traj)
Expand Down
19 changes: 18 additions & 1 deletion plotdigitizer/plotdigitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,28 @@ def digitize_plot(
"--output", "-o", help="Name of the output file (default <INPUT>.traj.csv)"
),
] = None,
remove_grid: Annotated[
bool,
typer.Option(
"--remove-grid",
"-rg",
help="Try to remove grid.",
),
] = False,
debug: Annotated[
bool,
typer.Option(
"--debug",
"-l",
help="Just analyze the image and dump coodinates. Useful when developing/debugging.",
),
] = False,
):
figure = image.Figure(infile, data_point, location)

# remove grids.
figure.remove_grid()
if remove_grid:
figure.remove_grid(debug)

# map the axis
figure.map_axis()
Expand Down

0 comments on commit b501375

Please sign in to comment.