Skip to content

Image Comparer

Source code in tools/comparer/img_comparer/img_comparer.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class ImageComparer:
    def __init__(self, settings: AppSettings):
        """
        An orchestrator for comparing two images using principial different algorithms.
        :param settings: settings object, includes default and user's params
        """
        super().__init__()
        self.settings = settings

        self.method_mapping = {
            Constants.dhash: DHash,
        }

        self.method = self.method_mapping[self.settings.method](
            settings=self.settings,
        )

        self.logger = LoggerConfigurator.setup(
            name=self.__class__.__name__,
            log_path=Path(self.settings.log_path) / f"{self.__class__.__name__}.log" if self.settings.log_path else None,
            log_level=self.settings.log_level
        )

    def compare(self, file_paths: Tuple[Path]):
        """
        compare files via each-with-each method
        :param file_paths: paths of files to be compared
        :return: matches that satisfy threshold condition
        """
        hash_map = self.method.get_hashmap(file_paths)
        matches = self.method.find_duplicates(hash_map)
        return matches

__init__(settings)

An orchestrator for comparing two images using principial different algorithms. :param settings: settings object, includes default and user's params

Source code in tools/comparer/img_comparer/img_comparer.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def __init__(self, settings: AppSettings):
    """
    An orchestrator for comparing two images using principial different algorithms.
    :param settings: settings object, includes default and user's params
    """
    super().__init__()
    self.settings = settings

    self.method_mapping = {
        Constants.dhash: DHash,
    }

    self.method = self.method_mapping[self.settings.method](
        settings=self.settings,
    )

    self.logger = LoggerConfigurator.setup(
        name=self.__class__.__name__,
        log_path=Path(self.settings.log_path) / f"{self.__class__.__name__}.log" if self.settings.log_path else None,
        log_level=self.settings.log_level
    )

compare(file_paths)

compare files via each-with-each method :param file_paths: paths of files to be compared :return: matches that satisfy threshold condition

Source code in tools/comparer/img_comparer/img_comparer.py
33
34
35
36
37
38
39
40
41
def compare(self, file_paths: Tuple[Path]):
    """
    compare files via each-with-each method
    :param file_paths: paths of files to be compared
    :return: matches that satisfy threshold condition
    """
    hash_map = self.method.get_hashmap(file_paths)
    matches = self.method.find_duplicates(hash_map)
    return matches