Speckle patterns and purity of quantum states