Equivalent for imadjust function from matlab

I am trying to find the equivalent function for the matlab imadjust function (https://www.mathworks.com/help/images/ref/imadjust.html)

I only need it for the default version: J=imadjust(I). The matlab documentation says that the command: J=imadjust(I) “By default, imadjust saturates the bottom 1% and the top 1% of all pixel values. This operation increases the contrast of the output image J .”

What is the equivalent function for this command in scikit-image. I have already tried:
p1, p99 = np.percentile(img, (1, 99))
J = exposure.rescale_intensity(I, in_range=(p1, p99))
and
J = exposure.equalize_adapthist(I)
but neither of these give the same output as the matlab J=imadjust(I) function.

Hi @awezm, I think you’re on the right track with

p1, p99 = np.percentile(img, (1, 99))
J = exposure.rescale_intensity(img, in_range=(p1, p99))

(I guess it was a typo that you had both img and I in the code sample?). The default value of the out_range parameter of rescale_intensity is dtype, meaning that the min and max values of the data type will be used. If you want to be sure you can specify a tuple for out_range, like (0, 255). In the matlab documentation page I had the impression that images were always in the range [0, 1], I’m not sure it’s the case in your Python case. I suspect that the discrepancy between matlab and python come either from a different data type or from a different intensity range for the original image.

If this is not the case, could you please paste here a small standalone example with a small array (eg 4x4), with its matlab output and its python output ?

1 Like