Prefoaming of poly(meth)acrylimide particles for subsequent foam moulding in closed tools