Can matplotlib patches with a function be used?

I am trying to build a series of .fits images in Python and apply a threshold rule so that only high-value pixels stand out. My threshold rule is as follows:

threshold = 7000
test = np.greater_equal(cropped_image, threshold)
plt.imshow(test)

Thus, I return a black and white image that displays all pixels above the threshold as white and all pixels below the black threshold. However, what I would like to do - instead of creating a separate image - is to impose a color above the pixels that exceeds the threshold value.

I understand that the matplotlib module patchesis capable of superimposing colors and shapes on images; however, it seems to patchesrequire the user to enter fixed coordinate values ​​that will indicate where the patch is located.

My question is, can it patchesbe changed so that patches can be placed above pixels that exceed the threshold? Or is there another module that would achieve this more efficiently? I haven’t found anything yet.

Thanks so much for any help!

+4
source share
1 answer

You just need to use the option alphato place the second image as an overlay:

threshold = 7000
test = np.greater_equal(cropped_image, threshold)
img1 = plt.imshow(cropped_image)
img2 = plt.imshow(test, alpha=.9)
plt.show()

Play with it (and with a color palette) to have the necessary display.

+3
source

Source: https://habr.com/ru/post/1682415/


All Articles