class_docstr: Find duplicates using hashing algorithms and/or generate hashes given a single image or a directory of images.
  
  The module can be used for 2 purposes: Encoding generation and duplicate detection.
  - Encoding generation:
  To generate hashes using specific hashing method. The generated hashes can be used at a later time for
  deduplication. Using the method 'encode_image' from the specific hashing method object, the hash for a
  single image can be obtained while the 'encode_images' method can be used to get hashes for all images in a
  directory.
  
  - Duplicate detection:
  Find duplicates either using the encoding mapping generated previously using 'encode_images' or using a Path to the
  directory that contains the images that need to be deduplicated. 'find_duplicates' and 'find_duplicates_to_remove'
  methods are provided to accomplish these tasks.
docstr: Find duplicates for each file. Takes in path of the directory or encoding dictionary in which duplicates are to
  be detected. All images with hamming distance less than or equal to the max_distance_threshold are regarded as
  duplicates. Returns dictionary containing key as filename and value as a list of duplicate file names.
  Optionally, the below the given hamming distance could be returned instead of just duplicate filenames for each
  query file.
  
  Args:
      image_dir: Path to the directory containing all the images or dictionary with keys as file names
                 and values as hash strings for the key image file.
      encoding_map: Optional,  used instead of image_dir, a dictionary containing mapping of filenames and
                    corresponding hashes.
      max_distance_threshold: Optional, hamming distance between two images below which retrieved duplicates are
                              valid. (must be an int between 0 and 64). Default is 10.
      scores: Optional, boolean indicating whether Hamming distances are to be returned along with retrieved duplicates.
      outfile: Optional, name of the file to save the results, must be a json. Default is None.
      search_method: Algorithm used to retrieve duplicates. Default is brute_force_cython for Unix else bktree.
      recursive: Optional, find images recursively in a nested image directory structure, set to False by default.
      num_enc_workers: Optional, number of cpu cores to use for multiprocessing encoding generation, set to number of CPUs in the system by default. 0 disables multiprocessing.
      num_dist_workers: Optional, number of cpu cores to use for multiprocessing distance computation, set to number of CPUs in the system by default. 0 disables multiprocessing.
  
  Returns:
      duplicates dictionary: if scores is True, then a dictionary of the form {'image1.jpg': [('image1_duplicate1.jpg',
                  score), ('image1_duplicate2.jpg', score)], 'image2.jpg': [] ..}. if scores is False, then a
                  dictionary of the form {'image1.jpg': ['image1_duplicate1.jpg', 'image1_duplicate2.jpg'],
                  'image2.jpg':['image1_duplicate1.jpg',..], ..}
  
  Example:
  ```
  from imagededup.methods import <hash-method>
  myencoder = <hash-method>()
  duplicates = myencoder.find_duplicates(image_dir='path/to/directory', max_distance_threshold=15, scores=True,
  outfile='results.json')
  
  OR
  
  from imagededup.methods import <hash-method>
  myencoder = <hash-method>()
  duplicates = myencoder.find_duplicates(encoding_map=<mapping filename to hashes>,
  max_distance_threshold=15, scores=True, outfile='results.json')
  ```
docstr_tok: ["Find","duplicates","for","each","file",".","Takes","in","path","of","the","directory","or","encoding","dictionary","in","which","duplicates","are","to","be","detected",".","All","images","with","hamming","distance","less","than","or","equal","to","the","max_distance_threshold","are","regarded","as","duplicates",".","Returns","dictionary","containing","key","as","filename","and","value","as","a","list","of","duplicate","file","names",".","Optionally",",","the","below","the","given","hamming","distance","could","be","returned","instead","of","just","duplicate","filenames","for","each","query","file",".","Args",":","image_dir",":","Path","to","the","directory","containing","all","the","images","or","dictionary","with","keys","as","file","names","and","values","as","hash","strings","for","the","key","image","file",".","encoding_map",":","Optional",",","used","instead","of","image_dir",",","a","dictionary","containing","mapping","of","filenames","and","corresponding","hashes",".","max_distance_threshold",":","Optional",",","hamming","distance","between","two","images","below","which","retrieved","duplicates","are","valid",".","(","must","be","an","int","between","0","and","64",")",".","Default","is","10.","scores",":","Optional",",","boolean","indicating","whether","Hamming","distances","are","to","be","returned","along","with","retrieved","duplicates",".","outfile",":","Optional",",","name","of","the","file","to","save","the","results",",","must","be","a","json",".","Default","is","None",".","search_method",":","Algorithm","used","to","retrieve","duplicates",".","Default","is","brute_force_cython","for","Unix","else","bktree",".","recursive",":","Optional",",","find","images","recursively","in","a","nested","image","directory","structure",",","set","to","False","by","default",".","num_enc_workers",":","Optional",",","number","of","cpu","cores","to","use","for","multiprocessing","encoding","generation",",","set","to","number","of","CPUs","in","the","system","by","default",".","0","disables","multiprocessing",".","num_dist_workers",":","Optional",",","number","of","cpu","cores","to","use","for","multiprocessing","distance","computation",",","set","to","number","of","CPUs","in","the","system","by","default",".","0","disables","multiprocessing",".","Returns",":","duplicates","dictionary",":","if","scores","is","True",",","then","a","dictionary","of","the","form","{","'image1.jpg","'",":","[","(","'image1_duplicate1.jpg","'",",","score",")",",","(","'image1_duplicate2.jpg","'",",","score",")","]",",","'image2.jpg","'",":","[","]","..","}",".","if","scores","is","False",",","then","a","dictionary","of","the","form","{","'image1.jpg","'",":","[","'image1_duplicate1.jpg","'",",","'image1_duplicate2.jpg","'","]",",","'image2.jpg","'",":","[","'image1_duplicate1.jpg","'",",","..","]",",","..","}","Example",":","``","`","from","imagededup.methods","import","<","hash-method",">","myencoder","=","<","hash-method",">","(",")","duplicates","=","myencoder.find_duplicates","(","image_dir='path\/to\/directory","'",",","max_distance_threshold=15",",","scores=True",",","outfile='results.json","'",")","OR","from","imagededup.methods","import","<","hash-method",">","myencoder","=","<","hash-method",">","(",")","duplicates","=","myencoder.find_duplicates","(","encoding_map=","<","mapping","filename","to","hashes",">",",","max_distance_threshold=15",",","scores=True",",","outfile='results.json","'",")","``","`"]
code: def find_duplicates(
      self,
      image_dir: PurePath = None,
      encoding_map: Dict[str, str] = None,
      max_distance_threshold: int = 10,
      scores: bool = False,
      outfile: Optional[str] = None,
      search_method: str = "brute_force_cython"
      if not sys.platform == "win32"
      else "bktree",
      recursive: Optional[bool] = False,
      num_enc_workers: int = cpu_count(),
      num_dist_workers: int = cpu_count(),
  ) -> Dict:
      """
      Find duplicates for each file. Takes in path of the directory or encoding dictionary in which duplicates are to
      be detected. All images with hamming distance less than or equal to the max_distance_threshold are regarded as
      duplicates. Returns dictionary containing key as filename and value as a list of duplicate file names.
      Optionally, the below the given hamming distance could be returned instead of just duplicate filenames for each
      query file.
  
      Args:
          image_dir: Path to the directory containing all the images or dictionary with keys as file names
                     and values as hash strings for the key image file.
          encoding_map: Optional,  used instead of image_dir, a dictionary containing mapping of filenames and
                        corresponding hashes.
          max_distance_threshold: Optional, hamming distance between two images below which retrieved duplicates are
                                  valid. (must be an int between 0 and 64). Default is 10.
          scores: Optional, boolean indicating whether Hamming distances are to be returned along with retrieved duplicates.
          outfile: Optional, name of the file to save the results, must be a json. Default is None.
          search_method: Algorithm used to retrieve duplicates. Default is brute_force_cython for Unix else bktree.
          recursive: Optional, find images recursively in a nested image directory structure, set to False by default.
          num_enc_workers: Optional, number of cpu cores to use for multiprocessing encoding generation, set to number of CPUs in the system by default. 0 disables multiprocessing.
          num_dist_workers: Optional, number of cpu cores to use for multiprocessing distance computation, set to number of CPUs in the system by default. 0 disables multiprocessing.
  
      Returns:
          duplicates dictionary: if scores is True, then a dictionary of the form {'image1.jpg': [('image1_duplicate1.jpg',
                      score), ('image1_duplicate2.jpg', score)], 'image2.jpg': [] ..}. if scores is False, then a
                      dictionary of the form {'image1.jpg': ['image1_duplicate1.jpg', 'image1_duplicate2.jpg'],
                      'image2.jpg':['image1_duplicate1.jpg',..], ..}
  
      Example:
      ```
      from imagededup.methods import <hash-method>
      myencoder = <hash-method>()
      duplicates = myencoder.find_duplicates(image_dir='path/to/directory', max_distance_threshold=15, scores=True,
      outfile='results.json')
  
      OR
  
      from imagededup.methods import <hash-method>
      myencoder = <hash-method>()
      duplicates = myencoder.find_duplicates(encoding_map=<mapping filename to hashes>,
      max_distance_threshold=15, scores=True, outfile='results.json')
      ```
      """
      self._check_hamming_distance_bounds(thresh=max_distance_threshold)
      if image_dir:
          result = self._find_duplicates_dir(
              image_dir=image_dir,
              max_distance_threshold=max_distance_threshold,
              scores=scores,
              outfile=outfile,
              search_method=search_method,
              recursive=recursive,
              num_enc_workers=num_enc_workers,
              num_dist_workers=num_dist_workers,
          )
      elif encoding_map:
          if recursive:
              warnings.warn(
                  "recursive parameter is irrelevant when using encodings.",
                  SyntaxWarning,
              )
  
          warnings.warn(
              "Parameter num_enc_workers has no effect since encodings are already provided",
              RuntimeWarning,
          )
  
          result = self._find_duplicates_dict(
              encoding_map=encoding_map,
              max_distance_threshold=max_distance_threshold,
              scores=scores,
              outfile=outfile,
              search_method=search_method,
              num_dist_workers=num_dist_workers,
          )
      else:
          raise ValueError(
              "Provide either an image directory or encodings!"
          )
      return result
  
imports: import os
  import sys
  import warnings
  from pathlib import PurePath, Path
  from typing import Dict, List, Optional
  from multiprocessing import cpu_count
  import numpy
  import pywt
  from scipy.fftpack import dct
  from imagededup.handlers.search.retrieval import HashEval
  from imagededup.utils.general_utils import get_files_to_remove, save_json, parallelise, generate_files, generate_relative_names
  from imagededup.utils.image_utils import load_image, preprocess_image, check_image_array_hash
  from imagededup.utils.logger import return_logger
label_desc: Use image node_id 10 for calling the Hashing obj's underlying member method code with example usage: obj.find_duplicates(image_dir, encoding_map, max_distance_threshold, scores, outfile, search_method, recursive, num_enc_workers, num_dist_workers) and returns: result