<p>What you're trying to do is change the pixel scale, but ultimately, you need to decrease the resolution of your image. I'm quite sure this can be done using a variety of image editing tools (even some free ones), but if you insist on doing this yourself, I can show you the general process. Let's say I have the image below, which for convenience is only 6x6 pixels in size.</p>

<p><a href="https://i.sstatic.net/mUEvT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mUEvT.png" alt="enter image description here"></a></p>

<p>I'll assume this image has a pixel scale of $p = 1\:\frac{''}{\text{pix}}$ and I want to convert it to an image with a pixel scale of $p'=1.5\:\frac{''}{\text{pix}}=1.5p$. This is effectively saying that I want the resolution of the image to decrease by a factor of $1.5$ and that each pixel in the $p'$ image will be comprised of $1.5^2$ pixels from the $p$ image. This is easily done by defining the new pixel grid over the old one and determining the new pixel "color" as the weighted mean of the old pixels which exist in your new, larger pixel.</p>

<p><a href="https://i.sstatic.net/BcKjk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BcKjk.png" alt="enter image description here"></a></p>

<p>For convenience, I'm going to define a coordinate system where the pixels are at position $(x,y)$ where $(0,0)$ is the top left pixel and $x$ and $y$ increase to the right and down respectively. This is a common coordinate system for images in programming.</p>

<p>Let's look at pixel $(0,0)$ in the $p'$ image. This is comprised of pixels $(0,0)$, $(1,0)$, $(0,1)$, and $(1,1)$ from the $p$ image. Specifically, the fractions of these pixels in our new pixel are $1$, $0.5$, $0.5$, and $0.25$ respectively. These fractions will become the weights.</p>

<p>What you need to do then is look at your four pixels in the $p$ image and determine their color/brightness/property-you're-trying-to-merge. For this simple case, I'll just use a number from zero (white) to one (black) that represents the magnitude of the pixel, but the same process applies no matter what your pixel information contains, be it an RGB value or whatever else. By looking at my four pixels in the $p$ image, I see the magnitudes are $0.05$, $0.05$, $0.25$, and $0.15$ respectively.</p>

<p>The new pixel's magnitude is then the weighted average of these.</p>

<p>$$p'_{00,\text{mag}} = \frac{1\times p_{00,\text{mag}} + 0.5\times p_{10,\text{mag}} + 0.5\times p_{01,\text{mag}} + 0.25\times p_{11,\text{mag}}}{1.5^2} = \frac{1\times 0.05 + 0.5\times 0.05 + 0.5\times 0.25 + 0.25\times 0.15}{1.5^2} = \boxed{0.1056}$$</p>

<p>The process is the same for each pixel in the $p'$ image. Hopefully you can see how this process would generalize for any new pixel scale. The hard part is determining where your new pixels will be and which pixels of your original image will comprise the new pixel. Once you know that, you simply average them together, weighted by the fraction of the original pixels that make up the new pixel. With a little bit of effort, this could all be fairly easily automated by a program and you'd only need to input the new pixel scale and the original image and it could output a new image at the new pixel scale.</p>

<p>One problem you might run into is that your new image can't be subdivided perfectly. E.g., if, in the above example, you wanted a new scale of $1.4$, you'd still wind up with a new $p'$ image of 4x4 pixels, but you'd only be able to cover 5.6x5.6 pixels of the original image and you'd necessarily have to cut off part of your image, thus losing some information. It'd be up to you to decide what you cut off.</p>

CC BY-SA 3.0
2016-11-02T18:27:39.220Z
This needs more upvotes. It's a really detailed answer.
Sir Cumference
CC BY-SA 3.0
2016-11-02T21:44:28.510Z
This would be just bilinear interpolation then, right? I think more complex schemes are used in practice.
ProfRob
CC BY-SA 3.0
2016-11-02T22:31:11.880Z
@RobJeffries Yep, pretty much. I just detailed one of the simplest implementable methods. There's many more but I figured, I have to start somewhere. I'd really suggest the OP use professional software instead of trying to recreate these algorithms from scratch.
zephyr
CC BY-SA 4.0
2021-04-09T03:02:38.403Z
@zephyr What professional software do you refer to? And when do you reckon that more complex schemes would be required?
Christian Herenz
CC BY-SA 3.0
2016-11-02T14:45:20.913Z
2016-12-06T19:04:10.793Z
2016-12-06T19:04:10.793Z
zephyr
<p>I'm in doubt whether I should put this in the astronomy or rather the coding exchange, but since my interest goes out to the former I will try my luck here.</p>

<p>Suppose I have an image with a certain pixel scale $x$. I would like to rebin this to a larger pixel scale, $y$, but this is not an integer multiple - so I can't say, for instance, that every group of 4 pixels in the original grid will now be one big pixel in the new grid, and average their flux.
Rather, I'd like something like i.e. $y=2.3\cdot x$.</p>

<p>Is this routinely done in the astronomical community -- and if so, how?</p>

CC BY-SA 3.0
2016-11-02T13:34:56.547Z
I think this question is slightly ambiguous since the term [pixel scale](http://www.cyanogen.com/help/maximdl/Pixel_Scale.htm) has a very particular meaning in astronomy that appears unrelated to what you're talking about. I think a more appropriate term would be "resolution".
zephyr
CC BY-SA 3.0
2016-11-02T13:43:58.687Z
One pixel in my image corresponds to $x$ arcseconds, isn't that exactly what the link you provide talks about - *Pixel scale is a measurement of how much of the sky is covered by one pixel.*?
user1991
CC BY-SA 3.0
2016-11-02T13:58:11.243Z
Yes, but that's beside the point. Even if your end result is to change the pixel scale, what you're ultimately changing in your image is the resolution as far as image processing goes. I'm just suggesting that the term resolution is more apt given your question.
zephyr
CC BY-SA 3.0
2016-11-02T14:37:22.530Z
This is very much a code problem, and there are dozens of kernel-based rescaling functions out there.  That's how your monitor can display an image whose x*y pixel count is different from your monitor's.
Carl Witthoft
CC BY-SA 3.0
2016-11-06T19:47:50.270Z
I did an astrophysics degree where this sort of thing was very much on the curriculum, this is definitely a valid question of practical astronomy
adrianmcmenamin
<data-analysis>
Rebinning with a non-integer factor
user1991
# Rebinning with a non-integer factor

(Asked by: username_0 on 2016-11-02)

I'm in doubt whether I should put this in the astronomy or rather the coding exchange, but since my interest goes out to the former I will try my luck here.

Suppose I have an image with a certain pixel scale $x$. I would like to rebin this to a larger pixel scale, $y$, but this is not an integer multiple - so I can't say, for instance, that every group of 4 pixels in the original grid will now be one big pixel in the new grid, and average their flux.
Rather, I'd like something like i.e. $y=2.3\cdot x$.

Is this routinely done in the astronomical community -- and if so, how?

**Tags:** data-analysis

> **Comments:**
> **username_1**: I think this question is slightly ambiguous since the term [pixel scale](http://www.cyanogen.com/help/maximdl/Pixel_Scale.htm) has a very particular meaning in astronomy that appears unrelated to what you're talking about. I think a more appropriate term would be "resolution".  
> **username_0**: One pixel in my image corresponds to $x$ arcseconds, isn't that exactly what the link you provide talks about - *Pixel scale is a measurement of how much of the sky is covered by one pixel.*?  
> **username_1**: Yes, but that's beside the point. Even if your end result is to change the pixel scale, what you're ultimately changing in your image is the resolution as far as image processing goes. I'm just suggesting that the term resolution is more apt given your question.  
> **username_2**: This is very much a code problem, and there are dozens of kernel-based rescaling functions out there.  That's how your monitor can display an image whose x*y pixel count is different from your monitor's.  
> **username_3**: I did an astrophysics degree where this sort of thing was very much on the curriculum, this is definitely a valid question of practical astronomy  

---

## 1 answers

### Answer by username_1 on 2016-11-02. Score: 3

What you're trying to do is change the pixel scale, but ultimately, you need to decrease the resolution of your image. I'm quite sure this can be done using a variety of image editing tools (even some free ones), but if you insist on doing this yourself, I can show you the general process. Let's say I have the image below, which for convenience is only 6x6 pixels in size.

[![enter image description here](https://i.sstatic.net/mUEvT.png)](https://i.sstatic.net/mUEvT.png)

I'll assume this image has a pixel scale of $p = 1\:\frac{''}{\text{pix}}$ and I want to convert it to an image with a pixel scale of $p'=1.5\:\frac{''}{\text{pix}}=1.5p$. This is effectively saying that I want the resolution of the image to decrease by a factor of $1.5$ and that each pixel in the $p'$ image will be comprised of $1.5^2$ pixels from the $p$ image. This is easily done by defining the new pixel grid over the old one and determining the new pixel "color" as the weighted mean of the old pixels which exist in your new, larger pixel.

[![enter image description here](https://i.sstatic.net/BcKjk.png)](https://i.sstatic.net/BcKjk.png)

For convenience, I'm going to define a coordinate system where the pixels are at position $(x,y)$ where $(0,0)$ is the top left pixel and $x$ and $y$ increase to the right and down respectively. This is a common coordinate system for images in programming.

Let's look at pixel $(0,0)$ in the $p'$ image. This is comprised of pixels $(0,0)$, $(1,0)$, $(0,1)$, and $(1,1)$ from the $p$ image. Specifically, the fractions of these pixels in our new pixel are $1$, $0.5$, $0.5$, and $0.25$ respectively. These fractions will become the weights.

What you need to do then is look at your four pixels in the $p$ image and determine their color/brightness/property-you're-trying-to-merge. For this simple case, I'll just use a number from zero (white) to one (black) that represents the magnitude of the pixel, but the same process applies no matter what your pixel information contains, be it an RGB value or whatever else. By looking at my four pixels in the $p$ image, I see the magnitudes are $0.05$, $0.05$, $0.25$, and $0.15$ respectively.

The new pixel's magnitude is then the weighted average of these.

$$p'\_{00,\text{mag}} = \frac{1\times p\_{00,\text{mag}} + 0.5\times p\_{10,\text{mag}} + 0.5\times p\_{01,\text{mag}} + 0.25\times p\_{11,\text{mag}}}{1.5^2} = \frac{1\times 0.05 + 0.5\times 0.05 + 0.5\times 0.25 + 0.25\times 0.15}{1.5^2} = \boxed{0.1056}$$

The process is the same for each pixel in the $p'$ image. Hopefully you can see how this process would generalize for any new pixel scale. The hard part is determining where your new pixels will be and which pixels of your original image will comprise the new pixel. Once you know that, you simply average them together, weighted by the fraction of the original pixels that make up the new pixel. With a little bit of effort, this could all be fairly easily automated by a program and you'd only need to input the new pixel scale and the original image and it could output a new image at the new pixel scale.

One problem you might run into is that your new image can't be subdivided perfectly. E.g., if, in the above example, you wanted a new scale of $1.4$, you'd still wind up with a new $p'$ image of 4x4 pixels, but you'd only be able to cover 5.6x5.6 pixels of the original image and you'd necessarily have to cut off part of your image, thus losing some information. It'd be up to you to decide what you cut off.

> **Comments:**
> **username_4**: This needs more upvotes. It's a really detailed answer.  
> **username_5**: This would be just bilinear interpolation then, right? I think more complex schemes are used in practice.  
> **username_1**: @RobJeffries Yep, pretty much. I just detailed one of the simplest implementable methods. There's many more but I figured, I have to start somewhere. I'd really suggest the OP use professional software instead of trying to recreate these algorithms from scratch.  
> **username_6**: @username_1 What professional software do you refer to? And when do you reckon that more complex schemes would be required?  

---

