

import math
import os

import cva
import numpy as np

A_		:			int										=   255.0


def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     float:






    '''simple docstring'''
    __UpperCAmelCase									=			np.mean((original - contrast) ** 2      )
    if mse == 0:
        return 1_0_0

    return 2_0 * math.logaa(PIXEL_MAX / math.sqrt(SCREAMING_SNAKE_CASE      )      )


def       __a       (   )      ->     None:






    '''simple docstring'''
    __UpperCAmelCase									=			os.path.dirname(os.path.realpath(SCREAMING_SNAKE_CASE      )      )
    # Loading images (original image and compressed image)
    __UpperCAmelCase									=			cva.imread(os.path.join(SCREAMING_SNAKE_CASE       ,   '''image_data/original_image.png'''      )      )
    __UpperCAmelCase									=			cva.imread(os.path.join(SCREAMING_SNAKE_CASE       ,   '''image_data/compressed_image.png'''      )       ,   1      )

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

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


if __name__ == "__main__":
       main()







import numpy as np


def       __a       (   SCREAMING_SNAKE_CASE      )      ->     Tuple:






    '''simple docstring'''
    __UpperCAmelCase					,     __UpperCAmelCase									=			a.shape
    __UpperCAmelCase									=			min(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )
    __UpperCAmelCase									=			np.eye(SCREAMING_SNAKE_CASE      )
    __UpperCAmelCase									=			a.copy()

    for k in range(t - 1      ):
        # select a column of modified matrix A':
        __UpperCAmelCase									=			r[k:, [k]]
        # construct first basis vector
        __UpperCAmelCase									=			np.zeros_like(SCREAMING_SNAKE_CASE      )
        __UpperCAmelCase									=			1.0
        # determine scaling factor
        __UpperCAmelCase									=			np.linalg.norm(SCREAMING_SNAKE_CASE      )
        # construct vector v for Householder reflection
        __UpperCAmelCase									=			x + np.sign(x[0]      ) * alpha * ea
        v /= np.linalg.norm(SCREAMING_SNAKE_CASE      )

        # construct the Householder matrix
        __UpperCAmelCase									=			np.eye(m - k      ) - 2.0 * v @ v.T
        # pad with ones and zeros as necessary
        __UpperCAmelCase									=			np.block([[np.eye(SCREAMING_SNAKE_CASE      ), np.zeros((k, m - k)      )], [np.zeros((m - k, k)      ), q_k]]      )

        __UpperCAmelCase									=			q @ q_k.T
        __UpperCAmelCase									=			q_k @ r

    return q, r


if __name__ == "__main__":
       import doctest

       doctest.testmod()




