"""simple docstring"""




import numpy as np
import torch
from imwatermark import WatermarkEncoder


# Copied from https://github.com/Stability-AI/generative-models/blob/613af104c6b85184091d42d374fef420eddb356d/scripts/demo/streamlit_helpers.py#L66
__lowerCAmelCase    :							Optional[int]													=						0b101100111110110010010000011110111011000110011110
# bin(x)[2:] gives bits of x as str, use int to convert them to 0/1
__lowerCAmelCase    :							str													=						[int(bit) for bit in bin(WATERMARK_MESSAGE)[2:]]

class       a_      :




					def __init__(	self						:     Union[str, Any]     ):
							lowerCAmelCase__        =   WATERMARK_BITS
							lowerCAmelCase__        =   WatermarkEncoder()

							self.encoder.set_watermark("""bits"""  ,						self.watermark     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Union[str, Any]  ,						snake_case__						:     torch.FloatTensor     ):
							# can't encode images that are smaller than 256
							if images.shape[-1] < 256:
									return images

							lowerCAmelCase__        =   (255 * (images / 2 + 0.5)).cpu().permute(0  ,						2  ,						3  ,						1     ).float().numpy()

							lowerCAmelCase__        =   [self.encoder.encode(snake_case__  ,						"""dwtDct"""     ) for image in images]

							lowerCAmelCase__        =   torch.from_numpy(np.array(snake_case__     )     ).permute(0  ,						3  ,						1  ,						2     )

							lowerCAmelCase__        =   torch.clamp(2 * (images / 255 - 0.5)  ,						min=-1.0  ,						max=1.0     )
							return images





"""simple docstring"""




import copy
import os

import cva
import numpy as np
from matplotlib import pyplot as plt

class       a_      :




					def __init__(	self						:     Optional[int]     ):
							lowerCAmelCase__        =   """"""
							lowerCAmelCase__        =   """"""
							lowerCAmelCase__        =   []
							lowerCAmelCase__        =   0
							lowerCAmelCase__        =   256
							lowerCAmelCase__        =   0
							lowerCAmelCase__        =   0
							lowerCAmelCase__        =   0
							lowerCAmelCase__        =   0




					def 						_SCREAMING_SNAKE_CASE						(	self						:     List[Any]  ,						snake_case__						:     Union[str, Any]     ):
							lowerCAmelCase__        =   cva.imread(snake_case__  ,						0     )
							lowerCAmelCase__        =   copy.deepcopy(self.img     )
							lowerCAmelCase__   ,					lowerCAmelCase__   ,					lowerCAmelCase__        =   plt.hist(self.img.ravel()  ,						256  ,						[0, 256]  ,						label="""x"""     )
							lowerCAmelCase__        =   np.sum(snake_case__     )
							for i in range(len(snake_case__     )     ):
									lowerCAmelCase__        =   x[i] / self.k
									self.sk += prk
									lowerCAmelCase__        =   (self.L - 1) * self.sk
									if self.rem != 0:
											lowerCAmelCase__        =   int(last % last     )
									lowerCAmelCase__        =   int(last + 1 if self.rem >= 0.5 else last     )
									self.last_list.append(snake_case__     )
									lowerCAmelCase__        =   int(np.ma.count(self.img     ) / self.img[1].size     )
									lowerCAmelCase__        =   self.img[1].size
							for i in range(self.number_of_cols     ):
									for j in range(self.number_of_rows     ):
											lowerCAmelCase__        =   self.img[j][i]
											if num != self.last_list[num]:
													lowerCAmelCase__        =   self.last_list[num]
							cva.imwrite("""output_data/output.jpg"""  ,						self.img     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):
							plt.hist(self.img.ravel()  ,						256  ,						[0, 256]     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):
							cva.imshow("""Output-Image"""  ,						self.img     )
							cva.imshow("""Input-Image"""  ,						self.original_image     )
							cva.waitKey(5000     )
							cva.destroyAllWindows()


if __name__ == "__main__":
			__lowerCAmelCase    :							Dict													=						os.path.join(os.path.basename(__file__), "image_data/input.jpg")
			__lowerCAmelCase    :							Optional[int]													=						ConstantStretch()
			stretcher.stretch(file_path)
			stretcher.plot_histogram()
			stretcher.show_image()




