





"""simple docstring"""
import math
import os

import cva
import numpy as np

__UpperCamelCase			:		Optional[int]		    =   2_55.0

def 						_SCREAMING_SNAKE_CASE       (_UpperCAmelCase :  float   ,			_UpperCAmelCase :  float       ):
 lowerCAmelCase  							=      np.mean((original - contrast) ** 2       )
 if mse == 0:
  return 100

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

def 						_SCREAMING_SNAKE_CASE       ():
 lowerCAmelCase  							=      os.path.dirname(os.path.realpath(_UpperCAmelCase       )       )
 # Loading images (original image and compressed image)
 lowerCAmelCase  							=      cva.imread(os.path.join(_UpperCAmelCase   ,			'image_data/original_image.png'       )       )
 lowerCAmelCase  							=      cva.imread(os.path.join(_UpperCAmelCase   ,			'image_data/compressed_image.png'       )   ,			1       )

 lowerCAmelCase  							=      cva.imread(os.path.join(_UpperCAmelCase   ,			'image_data/PSNR-example-base.png'       )       )
 lowerCAmelCase  							=      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()









import math as m







def   lowerCamelCase(      a__		,a__		,a__=0.001):
				return (f(a + h) - f(a - h)) / (2 * h)







def   lowerCamelCase(      a__		,a__=0		,a__=100		,a__=0.0001		,a__=1e-6		,a__=False):
				_SCREAMING_SNAKE_CASE	     =xa  # set the initial guess
				_SCREAMING_SNAKE_CASE	     =[a]
				_SCREAMING_SNAKE_CASE	     =abs(f(a__))
				_SCREAMING_SNAKE_CASE	     =lambda a__: calc_derivative(a__		,a__		,h=a__)  # noqa: E731  Derivative of f(x)
				for _ in range(a__):
								if fa(a__) == 0:
												raise ValueError('''No converging solution found''')
								_SCREAMING_SNAKE_CASE	     =a - f(a__) / fa(a__)  # Calculate the next estimate
								if logsteps:
												steps.append(a__)
								if error < maxerror:
												break
				else:
								raise ValueError('''Iteration limit reached, no converging solution found''')
				if logsteps:
								# If logstep is true, then log intermediate steps
								return a, error, steps
				return a, error


if __name__ == "__main__":
							from matplotlib import pyplot as plt

							snake_case_  :	Tuple							  =							lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
							snake_case_  , snake_case_  , snake_case_  :	str							  =							newton_raphson(
							    f, xa=10, maxiter=10_00, step=1e-6, logsteps=True
							)
							plt.plot([abs(f(x)) for x in steps])
							plt.xlabel('''step''')
							plt.ylabel('''error''')
							plt.show()
							print(f"""solution = {{{solution:f}}}, error = {{{error:f}}}""")