Reputation: 343
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!
Upvotes: 4
Views: 79
Reputation: 788
You just need to use the parameter alpha
to put your 2nd 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 the colormap) to have the display you need.
Upvotes: 3