Monday, 3 May 2021

Find Minimum Of Function That Takes Matrix As Input

Given a numpy array of shape (64,64) (=an image) and an arbitrary function that takes that image as an input, I want to find the image that minimizes the function. Let's say the function computes the contrast.

Example:

import numpy as np

def contrast(X):
    vmin, vmax = int(np.min(X)), int(np.max(X))
    num = vmax - vmin
    denom = vmax + vmin
    if denom == 0:
        return 0
    else:
        return num / denom

img = np.random.randint(256, size=(64,64), dtype=np.uint8)
res = contrast(img)

Scipy offers fmin(), but that function would not work with such a large input. Any ideas how to find the image that minimizes the function?



from Find Minimum Of Function That Takes Matrix As Input

No comments:

Post a Comment