Recovering the unsigned photospheric magnetic field from Ca II K observations