import multiprocessing
from tqdm import tqdm
import numpy as np
import imageio
import array
import os
import cv2

def generate_and_save_image(input_filename, output_filename, width=512):
    f = open(input_filename, 'rb')
    ln = os.path.getsize(input_filename)  # length of file in bytes
    if width == 0:
        width = ln
    rem = ln % width
    a = array.array("B")  # uint8 array
    a.fromfile(f, ln - rem)
    f.close()
    g = np.reshape(a, (len(a) // width, width))
    g = np.uint8(g)
    imageio.imwrite(output_filename, g)  # save the image 
    



    




