




"""simple docstring"""

import math
import os

import cva
import numpy as np

__A 		=			255.0



def   UpperCamelCase__     (		lowercase__  :     float       ,     lowercase__  :     float   ):
  snake_case		:						Tuple								=				np.mean((original - contrast) ** 2   )
  if mse == 0:
    return 100

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



def   UpperCamelCase__     (		):
  snake_case		:						Union[str, Any]								=				os.path.dirname(os.path.realpath(lowercase__   )   )
  # Loading images (original image and compressed image)
  snake_case		:						int								=				cva.imread(os.path.join(lowercase__       ,     "image_data/original_image.png"   )   )
  snake_case		:						List[Any]								=				cva.imread(os.path.join(lowercase__       ,     "image_data/compressed_image.png"   )       ,     1   )

  snake_case		:						int								=				cva.imread(os.path.join(lowercase__       ,     "image_data/PSNR-example-base.png"   )   )
  snake_case		:						Optional[int]								=				cva.imread(
      os.path.join(lowercase__       ,     "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(lowercase__       ,     lowercase__   )} dB'''   )

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


if __name__ == "__main__":
       main()







"""simple docstring"""

import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey
class 			lowerCamelCase__    :


			def __init__(     self				, SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					snake_case		:						int								=				0
					# max greyscale value for #FFFFFF
					snake_case		:						List[str]								=				int(self.get_greyscale(255				, 255				, 255							)							)

					if not self.min_threshold < threshold < self.max_threshold:
							snake_case		:						Union[str, Any]								=				F'''Factor value should be from 0 to {self.max_threshold}'''
							raise ValueError(SCREAMING_SNAKE_CASE							)

					snake_case		:						str								=				input_img
					snake_case		:						Optional[Any]								=				threshold
					snake_case			,				snake_case		:						List[str]								=				self.input_img.shape[1], self.input_img.shape[0]

					# error table size (+4 columns and +1 row) greater than input image because of
					# lack of if statements
					snake_case		:						Union[str, Any]								=				[
					    [0 for _ in range(self.height + 4							)] for __ in range(self.width + 1							)
					]
					snake_case		:						Tuple								=				np.ones((self.width, self.height, 3)				, np.uinta							) * 255


			@classmethod
			def 							lowerCamelCase_				(     cls				, SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					return 0.1_14 * blue + 0.5_87 * green + 0.21_26 * red



			def 							lowerCamelCase_				(     self							):



					"""simple docstring"""







					for y in range(self.height							):
							for x in range(self.width							):
									snake_case		:						Dict								=				int(self.get_greyscale(*self.input_img[y][x]							)							)
									if self.threshold > greyscale + self.error_table[y][x]:
											snake_case		:						List[str]								=				(0, 0, 0)
											snake_case		:						List[Any]								=				greyscale + self.error_table[x][y]
									else:
											snake_case		:						int								=				(255, 255, 255)
											snake_case		:						Tuple								=				greyscale + self.error_table[x][y] - 255
									self.error_table[y][x + 1] += int(8 / 32 * current_error							)
									self.error_table[y][x + 2] += int(4 / 32 * current_error							)
									self.error_table[y + 1][x] += int(8 / 32 * current_error							)
									self.error_table[y + 1][x + 1] += int(4 / 32 * current_error							)
									self.error_table[y + 1][x + 2] += int(2 / 32 * current_error							)
									self.error_table[y + 1][x - 1] += int(4 / 32 * current_error							)
									self.error_table[y + 1][x - 2] += int(2 / 32 * current_error							)


if __name__ == "__main__":
							# create Burke's instances with original images in greyscale
							__A 		=			[
							    Burkes(imread("image_data/lena.jpg", 1), threshold)
							    for threshold in (1, 126, 130, 140)
							]

							for burkes in burkes_instances:
														burkes.process()

							for burkes in burkes_instances:
														imshow(
														    f'Original image with dithering threshold: {burkes.threshold}',
														    burkes.output_img,
														)

							waitKey(0)
							destroyAllWindows()

