diff --git a/image_prediction/stitching/merging.py b/image_prediction/stitching/merging.py index fc557ef..87bc673 100644 --- a/image_prediction/stitching/merging.py +++ b/image_prediction/stitching/merging.py @@ -10,7 +10,7 @@ from image_prediction.info import Info from image_prediction.stitching.grouping import CoordGrouper from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once from image_prediction.utils.generic import until -from test.utils.stitching import HorizontalSplitMapper, VerticalMapper +from image_prediction.stitching.split_mapper import HorizontalSplitMapper, VerticalMapper def no_new_merges(pairs1, pairs2): diff --git a/image_prediction/stitching/split_mapper.py b/image_prediction/stitching/split_mapper.py new file mode 100644 index 0000000..95b1470 --- /dev/null +++ b/image_prediction/stitching/split_mapper.py @@ -0,0 +1,49 @@ +import abc + +from image_prediction.info import Info + + +class SplitMapper(abc.ABC): + def __init__(self, wrapped: dict, keymap: dict): + self.wrapped = wrapped + self.keymap = keymap + + def __getitem__(self, key): + return self.wrapped[self.keymap[key]] + + def __setitem__(self, key, value): + self.wrapped[self.keymap[key]] = value + + @property + def dim(self): + return self["dim"] + + @dim.setter + def dim(self, value): + self["dim"] = value + + @property + def c1(self): + return self["c1"] + + @c1.setter + def c1(self, value): + self["c1"] = value + + @property + def c2(self): + return self["c2"] + + @c2.setter + def c2(self, value): + self["c2"] = value + + +class HorizontalSplitMapper(SplitMapper): + def __init__(self, wrapped: dict): + super().__init__(wrapped, {"dim": Info.WIDTH, "c1": Info.X1, "c2": Info.X2}) + + +class VerticalMapper(SplitMapper): + def __init__(self, wrapped: dict): + super().__init__(wrapped, {"dim": Info.HEIGHT, "c1": Info.Y1, "c2": Info.Y2}) \ No newline at end of file diff --git a/test/utils/stitching.py b/test/utils/stitching.py index 9bb2df0..eb41797 100644 --- a/test/utils/stitching.py +++ b/test/utils/stitching.py @@ -1,57 +1,10 @@ -import abc import random from copy import deepcopy from itertools import chain from funcy import rpartial, juxt -from image_prediction.info import Info - - -class SplitMapper(abc.ABC): - def __init__(self, wrapped: dict, keymap: dict): - self.wrapped = wrapped - self.keymap = keymap - - def __getitem__(self, key): - return self.wrapped[self.keymap[key]] - - def __setitem__(self, key, value): - self.wrapped[self.keymap[key]] = value - - @property - def dim(self): - return self["dim"] - - @dim.setter - def dim(self, value): - self["dim"] = value - - @property - def c1(self): - return self["c1"] - - @c1.setter - def c1(self, value): - self["c1"] = value - - @property - def c2(self): - return self["c2"] - - @c2.setter - def c2(self, value): - self["c2"] = value - - -class HorizontalSplitMapper(SplitMapper): - def __init__(self, wrapped: dict): - super().__init__(wrapped, {"dim": Info.WIDTH, "c1": Info.X1, "c2": Info.X2}) - - -class VerticalMapper(SplitMapper): - def __init__(self, wrapped: dict): - super().__init__(wrapped, {"dim": Info.HEIGHT, "c1": Info.Y1, "c2": Info.Y2}) +from image_prediction.stitching.split_mapper import SplitMapper, HorizontalSplitMapper, VerticalMapper class BoxSplitter: