

import math
import os

import cva
import numpy as np

lowerCAmelCase						:   str										=    255.0





def 			_lowercase    (      __UpperCamelCase     :		float   ,       __UpperCamelCase     :		float ):
      snake_case__					=   np.mean((original - contrast) ** 2 )
      if mse == 0:
            return 100

      return 20 * math.logaa(PIXEL_MAX / math.sqrt(__UpperCamelCase ) )





def 			_lowercase    (      ):
      snake_case__					=   os.path.dirname(os.path.realpath(__UpperCamelCase ) )
      # Loading images (original image and compressed image)
      snake_case__					=   cva.imread(os.path.join(__UpperCamelCase   ,       """image_data/original_image.png""" ) )
      snake_case__					=   cva.imread(os.path.join(__UpperCamelCase   ,       """image_data/compressed_image.png""" )   ,       1 )

      snake_case__					=   cva.imread(os.path.join(__UpperCamelCase   ,       """image_data/PSNR-example-base.png""" ) )
      snake_case__					=   cva.imread(
          os.path.join(__UpperCamelCase   ,       """image_data/PSNR-example-comp-10.jpg""" )   ,       1 )

      # Value expected: 29.73dB
      print("""-- First Test --""" )
      print(F'''PSNR value is {peak_signal_to_noise_ratio(__UpperCamelCase   ,       __UpperCamelCase )} dB''' )

      # # Value expected: 31.53dB (Wikipedia Example)
      print("""\n-- Second Test --""" )
      print(F'''PSNR value is {peak_signal_to_noise_ratio(__UpperCamelCase   ,       __UpperCamelCase )} dB''' )


if __name__ == "__main__":
       main()









lowerCAmelCase						:   Optional[Any]										=    1000





def 			_lowercase    (      __UpperCamelCase     :		float ):
      return x * x





def 			_lowercase    (      __UpperCamelCase     :		int   ,       __UpperCamelCase     :		float   ,       __UpperCamelCase     :		float   ,       __UpperCamelCase     :		int = 4 ):
      assert callable(
          __UpperCamelCase ), F'''the function(object) passed should be callable your input : {function}'''
      assert isinstance(__UpperCamelCase   ,       (float, int) ), F'''a should be float or integer your input : {a}'''
      assert isinstance(function(__UpperCamelCase )   ,       (float, int) ), (
          "the function should return integer or float return type of your function, "
          F'''{type(__UpperCamelCase )}'''
      )
      assert isinstance(__UpperCamelCase   ,       (float, int) ), F'''b should be float or integer your input : {b}'''
      assert (
          isinstance(__UpperCamelCase   ,       __UpperCamelCase ) and precision > 0
      ), F'''precision should be positive integer your input : {precision}'''

      # just applying the formula of simpson for approximate integration written in
      # mentioned article in first comment of this file and above this function

      snake_case__					=   (b - a) / N_STEPS
      snake_case__					=   function(__UpperCamelCase ) + function(__UpperCamelCase )

      for i in range(1   ,       __UpperCamelCase ):
            snake_case__					=   a + h * i
            result += function(__UpperCamelCase ) * (4 if i % 2 else 2)

      result *= h / 3
      return round(__UpperCamelCase   ,       __UpperCamelCase )


if __name__ == "__main__":
       import doctest

       doctest.testmod()






