We present a systematic study of the optical contrast of niobium diselenide and molybdenum disulfide flakes deposited onto silicon wafers with a thermally grown silicon oxide layer. We measure the optical contrast of flakes whose thickness, which is obtained by atomic force microscopy, ranges from 200 layers down to a monolayer using different illumination wavelengths in the visible spectrum. The refractive index of these thin crystals has been obtained from the optical contrast using Fresnel law. In this way the optical microscopy data can be quantitatively analyzed to determine the thickness of the flakes in a fast and nondestructive way.