


'''simple docstring'''






from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import array, dot, pad, ravel, uinta, zeros






def 						_A					(lowerCAmelCase__	:Optional[Any]					,    lowerCAmelCase__	:Tuple		) ->	Dict:




     '''simple docstring'''



     _a         =				image.shape
     _a         =				cols - block_size[1] + 1
     _a         =				rows - block_size[0] + 1
     _a         =				zeros((dst_height * dst_width, block_size[1] * block_size[0])		)
     _a         =				0
     for i in range(0					,    lowerCAmelCase__		):
          for j in range(0					,    lowerCAmelCase__		):
               _a         =				ravel(image[i : i + block_size[0], j : j + block_size[1]]		)
               _a         =				window
               row += 1

     return image_array






def 						_A					(lowerCAmelCase__	:str					,    lowerCAmelCase__	:List[str]		) ->	List[Any]:




     '''simple docstring'''



     _a         =				image.shape[0], image.shape[1]
     _a         =				filter_kernel.shape[0]
     _a         =				k_size // 2
     # Pads image with the edge values of array.
     _a         =				pad(lowerCAmelCase__					,    lowerCAmelCase__					,    mode='edge'		)

     # im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
     _a         =				imacol(lowerCAmelCase__					,    (k_size, k_size)		)

     #  turn the kernel into shape(k*k, 1)
     _a         =				ravel(lowerCAmelCase__		)
     # reshape and get the dst image
     _a         =				dot(lowerCAmelCase__					,    lowerCAmelCase__		).reshape(lowerCAmelCase__					,    lowerCAmelCase__		)
     return dst


if __name__ == "__main__":
 # read original image
 a_       :     str 							=     imread(R"../image_data/lena.jpg")
 # turn image in gray scale value
 a_       :     Any 							=     cvtColor(img, COLOR_BGR2GRAY)
 # Laplace operator
 a_       :     Dict 							=     array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
 a_       :     Dict 							=     img_convolve(gray, Laplace_kernel).astype(uinta)
 imshow("Laplacian", out)
 waitKey(0)









"""simple docstring"""





from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
UpperCamelCase_						:					int      				=			[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]



def      __lowercase       (     a			:					int			)       ->       list[int]:
      return [int(a			) for c in f'''{ruleset:08}'''[:8]]



def      __lowercase       (     a			:					list[list[int]]							,		a			:					list[int]							,		a			:					int			)       ->       list[int]:
      __snake_case   :     Optional[Any]	      =len(cells[0]			)  # 31
      __snake_case   :     List[str]	      =[]
      for i in range(a			):
            # Get the neighbors of each cell
            # Handle neighbours outside bounds by using 0 as their value
            __snake_case   :     Optional[Any]	      =0 if i == 0 else cells[time][i - 1]
            __snake_case   :     Dict	      =0 if i == population - 1 else cells[time][i + 1]
            # Define a new cell and add it to the new generation
            __snake_case   :     Optional[int]	      =7 - int(f'''{left_neighbor}{cells[time][i]}{right_neighbor}'''							,		2			)
            next_generation.append(rule[situation]			)
      return next_generation



def      __lowercase       (     a			:					list[list[int]]			)       ->       Image.Image:
      __snake_case   :     int	      =Image.new('''RGB'''							,		(len(cells[0]			), len(a			))			)
      __snake_case   :     List[Any]	      =img.load()
      # Generates image
      for w in range(img.width			):
            for h in range(img.height			):
                  __snake_case   :     int	      =255 - int(255 * cells[h][w]			)
                  __snake_case   :     List[str]	      =(color, color, color)
      return img


if __name__ == "__main__":
    UpperCamelCase_						:					Optional[Any]      				=			bin(int(input("""Rule:\n""").strip()))[2:]
    UpperCamelCase_						:					List[str]      				=			format_ruleset(int(rule_num))
    for time in range(16):
        CELLS.append(new_generation(CELLS, rule, time))
    UpperCamelCase_						:					List[Any]      				=			generate_image(CELLS)
    # Uncomment to save the image
    # img.save(f"rule_{rule_num}.png")
    img.show()


