<p>You can use the <a href="https://reproject.readthedocs.io/en/stable/" rel="noreferrer">reproject</a> package to interpolate two of the fits files onto the WCS of the third file.</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import astropy.visualization
import reproject

fdata hdu1[0].data

ndata, _ = reproject.reproject_interp(hdu2[0], hdu1[0].header)

datat, _ = reproject.reproject_interp(hdu3[0], hdu1[0].header)

image_rgb = astropy.visualization.make_lupton_rgb(fdata, ndata, datat, filename=&quot;qw.jpeg)
</code></pre>
<p>This is just an example, make sure to choose to interpolate onto the coordinate system of whatever image you desire.</p>

CC BY-SA 4.0
2023-02-01T16:21:57.417Z
2023-02-01T16:40:39.817Z
2023-02-01T16:40:39.817Z
Roy Smart
<p>I want to make an RGB image using 3 FITS files: one IR image from <em>Spitzer</em> and the other two from <em>UVIT</em>. I tried to make them using <strong>make_lupton_rgb</strong> in <em>Astropy</em>, but it doesn't work in the case of FITS files with unequal dimensions. I tried to use DS9, but I cannot export the resultant RGB image due to different dimensions. How do I get around this?</p>
<pre><code>hdu1 = fits.open('fuv_.fits')
fdata = hdu1[0].data
w1 = wcs.WCS(hdu1[0].header)
    
hdu2 = fits.open('nuvcrop.fits')
ndata = hdu2[0].data
w2 = wcs.WCS(hdu2[0].header)

hdu3=fits.open('_IRAC_3.6.fits')
datat = hdu3[0].data

fig = plt.figure(figsize=(40, 40))
ax = plt.subplot(projection=w2)

rgb_default = make_lupton_rgb(0.5*ndata, 0.5*ndata,3*fdata)#, filename=&quot;qw.jpeg&quot;)
plt.imshow(datat, origin='lower')
<span class="math-container">```</span>
</code></pre>

CC BY-SA 4.0
2023-02-01T15:28:02.413Z
An RGB image consists of three values _per pixel_, so your three images need some values for these pixels. Unless I misunderstand, isn't it just a question of interpolating your three images to a common grid?
pela
<fits><color>
Making RGB image using FITS files with different dimensions
SlightDecoy
# Making RGB image using FITS files with different dimensions

(Asked by: username_0 on 2023-02-01)

I want to make an RGB image using 3 FITS files: one IR image from Spitzer and the other two from UVIT. I tried to make them using make_lupton_rgb in Astropy, but it doesn't work in the case of FITS files with unequal dimensions. I tried to use DS9, but I cannot export the resultant RGB image due to different dimensions. How do I get around this?
hdu1 = fits.open('fuv_.fits')
fdata = hdu1[0].data
w1 = wcs.WCS(hdu1[0].header)
    
hdu2 = fits.open('nuvcrop.fits')
ndata = hdu2[0].data
w2 = wcs.WCS(hdu2[0].header)

hdu3=fits.open('_IRAC_3.6.fits')
datat = hdu3[0].data

fig = plt.figure(figsize=(40, 40))
ax = plt.subplot(projection=w2)

rgb_default = make_lupton_rgb(0.5*ndata, 0.5*ndata,3*fdata)#, filename="qw.jpeg")
plt.imshow(datat, origin='lower')
```

**Tags:** fits, color

> **Comments:**
> **username_1**: An RGB image consists of three values _per pixel_, so your three images need some values for these pixels. Unless I misunderstand, isn't it just a question of interpolating your three images to a common grid?  

---

## 1 answers

### Answer by username_2 on 2023-02-01. Score: 5 | Accepted answer

You can use the reproject package to interpolate two of the fits files onto the WCS of the third file.
import numpy as np
import matplotlib.pyplot as plt
import astropy.visualization
import reproject

fdata hdu1[0].data

ndata, _ = reproject.reproject_interp(hdu2[0], hdu1[0].header)

datat, _ = reproject.reproject_interp(hdu3[0], hdu1[0].header)

image_rgb = astropy.visualization.make_lupton_rgb(fdata, ndata, datat, filename="qw.jpeg)

This is just an example, make sure to choose to interpolate onto the coordinate system of whatever image you desire.


---

