import numpy as np
import matplotlib.pyplot as plt
import imageio.v3 as iio

def norm_minmax(img, C, m):
    img = (img - img.min())/(img.max() - img.min())
    img *= C
    img -= m
    return img

def main():
    img = iio.imread('small.jpeg')
    # plt.imshow(img)
    # plt.show()

    img = 0.25*img[..., 0] + 0.5*img[..., 1] + 0.25*img[..., 2]

    plt.imshow(img, cmap='grey')
    plt.show()

    inv = 255 - img

    c = 255/(np.log(img.max()+1))
    log = c*np.log(img)

    img_norm = norm_minmax(img.astype(float), 1.0, 0)
    gamma = 2.0
    gamma_img = img_norm**gamma
    gamma_img = norm_minmax(gamma_img, 255, 0).astype(np.uint8)


    thresholds = 42, 120
    threshold_img = np.zeros_like(img)
    threshold_img[(img > thresholds[0]) & (img < thresholds[1])] = 255

    x = np.arange(-1, 1, 0.01)
    y = 1/(1 + np.exp(-10*x))

    plt.plot(x, y)
    plt.show()

    img_norm = norm_minmax(img.astype(float), 2.0, -1.0)
    img_sig = 1/(1 + np.exp(-10*img_norm))
    img_sig = norm_minmax(img_sig, 255, 0).astype(np.uint8)

    plt.imshow(img_sig, cmap='grey')
    plt.show()


if __name__ == "__main__":
    main()
