The measurement of the RMS emittance of an ion beam with an arbitrary density profile