This paper discusses a technique for improving the homogeneity of the magnetic field in structures of permanent magnets designed for magnetic resonance imaging, achieved by inserting layers of ferromagnetic plates and permanent magnets along the cavity of the structure. The analysis of the field in the magnet is performed using a boundary integral equation method. An example of optimization of the geometry and the amount of the magnetic material is presented.