1

I hope this will be a pretty straight forward question. I am working on processing some images that I read in from FITS files into numpy arrays. I want to make an RGB image. The issue is that when I make the RGB image, there is this 'white haze' that seems to appear. Alternatively, I know that the areas that are black should be black in this image, but instead they look grey. The greens from the G image are coming through pretty nicely. It just looks like there is a white haze or fog over the whole image. I thought maybe it was an issue with setting alpha? Note setting the A in RBGA to 0 and 255 didn't help the issue.

Here is an image example -- I would show it except I do not have enough reputation points. Unfortunately in this case a picture is worth a 1000 words...

And here is the code I am using to do this image processing:

testrgb = np.zeros([512,512,4])
# 
# converting read in image to float
tmpr = asi1r.astype('float')
tmpg = asi1g.astype('float')
tmpb = asi1b.astype('float')


#http://akash0x53.github.io/blog/2013/04/29/normalization/ pretty obvious
tmptotal = tmpr+tmpg+tmpb
R = tmpr/tmptotal
G = tmpg/tmptotal
B = tmpb/tmptotal

# eliminate the nans in the division
R[np.isnan(R) == True] = 0.
G[np.isnan(G) == True] = 0.
B[np.isnan(B) == True] = 0.

testrgb[:,:,0] = R*255.
testrgb[:,:,1] = G*255. #asi1g.astype('float')
testrgb[:,:,2] = B*255. #asi1b.astype('float')
testrgb[:,:,3] = 255.

testrgb = testrgb.astype('uint8')

f = plt.figure(figsize=(4,4), dpi=300)
plt.imshow(testrgb,cmap='jet',vmin=0,vmax=200)
plt.colorbar()
plt.show()
f.savefig('test.png')
plt.close('all')

Any help would be appreciated. Thank you.

AD0AE
  • 91
  • 5
  • Why are you using `vmin=0,vmax=200` rather than `vmin=0,vmax=255` in `plt.imshow`? – Dan D. Dec 07 '14 at 04:21
  • I was just trying to play with the range of imshow, doing some trial and error to see if it would change anything. – AD0AE Dec 07 '14 at 04:47
  • Since you can't show an image, it would be *really* helpful if you included a complete, working example in the question, so we could try to reproduce the image. Currently, `asi1r`, `asi1g` and `asi1b` are undefined. – Warren Weckesser Dec 07 '14 at 07:31
  • Have you tried setting `interpolation='none'` in `imshow`? – tiago Dec 07 '14 at 09:23
  • Thank you all for the help so far... just a couple of things. 1) @tiago I have tried interpolation='none' and it did not change anything. In playing with it this morning, I think the issue may have to do more with how I am doing the normalization of the data. Ideally, in the corners, where I know the data should be 'black' (0,0,0), I am getting numbers that are more like (0.33,0.33,0.33) (in float 0-1 notation). Also in checking [link](http://www.rapidtables.com/web/color/RGB_Color.htm) I am probably not background subtracting the data properly. Any suggestions? – AD0AE Dec 07 '14 at 18:03
  • For my astronomical images, I use `APLpy` to construct RGB images from fits files, which is very straightforward. Have you tried it? – skytux Dec 07 '14 at 22:44

1 Answers1

1

This doesn't seem to be a problem with matplotlib. From your comments it seems indeed that the normalisation is wrong. Try the following:

tmptotal = tmpr + tmpg + tmpb
testrgb[..., 0] = tmpr 
testrgb[..., 1] = tmpg 
testrgb[..., 2] = tmpb 

testrgb *= (255.*3) / tmptotal

imshow(testrgb, cmap='jet')

The vmax and vmin settings are not applicable to RGB images.

tiago
  • 22,602
  • 12
  • 72
  • 88