def _minimize(self, x: np.ndarray, mask: np.ndarray) -> np.ndarray:
        """
        Minimize the total variance objective function.

        :param x: Original image.
        :param mask: A matrix that decides which points are kept.
        :return: A new image.
        """
        z_min = x.copy()

        for i in range(x.shape[2]):
            res = minimize(
                self._loss_func,
                z_min[:, :, i].flatten(),
                (x[:, :, i], mask[:, :, i], self.norm, self.lamb),
                method=self.solver,
                jac=self._deri_loss_func,
                options={"maxiter": self.max_iter},
            )
            z_min[:, :, i] = np.reshape(res.x, z_min[:, :, i].shape)

        return z_min

        Minimize the total variance objective function.

        :param x: Original image.
        :param mask: A matrix that decides which points are kept.
        :return: A new image.
        
art/defences/preprocessor/variance_minimization.py