4

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!

asked Jul 27, 2017 at 14:14

1 Answer 1

3

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.

answered Jul 27, 2017 at 14:44

2 Comments

Thank you, this worked very well! Is alpha the command that creates the overlay?
alpha is the opacity. alpha=0.9 means 90% opaque, or 10% transparent.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.