Can matplotlib patches be used with a function?

Viewed 56

I am attempting to plot a series of .fits images in Python, and apply a thresholding rule so that only high-value pixels are highlighted. My thresholding rule is as follows:

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

In this way, I return a black/white image that displays all the pixels greater than threshold values as white, and all pixels lower than threshold as black. However, what I would like to do - instead of plotting a separate image - is to overlay a colour above pixels that exceed the threshold value.

I understand that the matplotlib module patches is able to overlay colours and shapes on images; however, it appears that patches requires the user to input fixed co-ordinate values that will specify where the patch is placed.

My question is, can patches be modified so that patches can be placed over pixels exceeding a threshold value? Or is there another module that would achieve this more efficiently? I have not found anything so far.

Many thanks for any help!

1 Answers
Related