<p><strong><em>"Downscaling by skipping rows and columns – any example images?"</em></strong></p>

<p>You asked for example images: The following is a sequence of 50 frames from a well known (and hopefully freely available) sequence, subsampled as you suggested.</p>

<p>I think you might find simply subsampling/decimating to be a bit too noisy. </p>

<p>Are you sure you can't at least do some box filtering?</p>

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

CC BY-SA 3.0
2017-01-13T17:45:04.403Z
I now established that I will use stm32f767 which – not looked myself yet – has DSP commands. I might do some computations after all, clock is 216 MHz and DMA is said to be flexible. I will read ADV7280 output clocked at 54 MHz, though (interlace -> progressive enabled).
Gortu
CC BY-SA 3.0
2017-01-13T14:48:55.407Z
2017-01-13T15:40:26.613Z
2017-01-13T15:40:26.613Z
Simon F
<p>A basic nearest neighbour scale function would work like so. Here I also use 24:8 fixed point arithmetic to make it more micro friendly. </p>

<pre><code>const int originalWidth = 320, originalHeight = 240;
int targetWidth = 50, targetHeight = 50;

char *pSource = sourceBuffer; 
char *pDest = destBuffer;    // you can use RGB instead of char

int yStep = (originalWidth &lt;&lt; 8) / targetWidth;
int xStep = (originalHeight &lt;&lt; 8) / targetHeight;

for(int y = 0, sampleY = 0; y &lt; targetHeight; y++, sampleY += yStep) {
    // Point to start of scaled Y source line
    char *pSourceLine = pSource + ((sampleY &gt;&gt; 8) * originalWidth);

    // Output the line, scaling only in X (we already know scaled-Y)
    for(int x = 0, sampleX = 0; x &lt; targetWidth; x++, sampleX += xStep)
        *pDest++ = pSourceLine[sampleX &gt;&gt; 8];
}
</code></pre>

<p>This will also work to scale image up as well as down, it should work on any input vs output size.</p>

CC BY-SA 3.0
2017-01-13T06:18:55.530Z
2017-01-13T06:18:55.530Z
PaulHK
<p>I'm about to implement downscaling on a microcontroller. Source resolution is e.g. 720x576 (the 576i PAL resolution, other one possible: 480i, NTSC resolution), destination is 32x16. The goal is to have RGB LED matrix (of size 32x16) flowing with various colors, shapes, shadows, etc. – a half-abstract vs. half-meaningful effect, driven by a prepared PAL or NTSC video.</p>

<p>I will only be able to select every 22th pixel (720 / 36) and every 36th line (576 / 16) – the microcontroller will not be able to compute averages of groups of pixels etc. This way I will obtain 32x16 downscaled image to output to the LED matrix.</p>

<p>I cannot find any examples of how such downscaling will behave. Tried searching for "decimation" but no luck. Which program can I use to test this downscaling? Can I quickly code this somehow – if I would to code this, I would use libSDL1, generate set of files, but this is difficult (e.g. image loading). Maybe some snippet-solution is possible? Should I care about Nyquist frequency?</p>

CC BY-SA 3.0
2017-01-10T22:36:30.300Z
Using a paint program that has a "nearest neighbor" resize mode would give you a quick approximation, though it may not select the exact same rows/columns as your code. I think it would be pretty easy to prototype in Python using [pillow](https://python-pillow.org/) for image manipulation.
Nathan Reed
CC BY-SA 3.0
2017-01-11T09:40:47.443Z
*"I cannot find any examples of how such downscaling will behave."*   Did you ever play old 3D games like Doom and see the hideous aliasing artefacts on walls/objects in the distance? That's what it will be like.
Simon F
CC BY-SA 3.0
2017-01-15T03:34:38.620Z
Note that PAL and NTSC are a 4:3 aspect ratio (despite NTSC seeming like 3:2  - it has non-square pixels at 720x480). 32x16 is 2:1, so you will either be stretching the video, or pillar boxing it. In my opinion, pillar box is far better, but given the abstractness of your description, maybe you'd prefer to stretch it?
user1118321
<image-processing><noise><sampling>
Downscaling by skipping rows and columns – any example images?
Gortu
# Downscaling by skipping rows and columns – any example images?

(Asked by: username_0 on 2017-01-10)

I'm about to implement downscaling on a microcontroller. Source resolution is e.g. 720x576 (the 576i PAL resolution, other one possible: 480i, NTSC resolution), destination is 32x16. The goal is to have RGB LED matrix (of size 32x16) flowing with various colors, shapes, shadows, etc. – a half-abstract vs. half-meaningful effect, driven by a prepared PAL or NTSC video.

I will only be able to select every 22th pixel (720 / 36) and every 36th line (576 / 16) – the microcontroller will not be able to compute averages of groups of pixels etc. This way I will obtain 32x16 downscaled image to output to the LED matrix.

I cannot find any examples of how such downscaling will behave. Tried searching for "decimation" but no luck. Which program can I use to test this downscaling? Can I quickly code this somehow – if I would to code this, I would use libSDL1, generate set of files, but this is difficult (e.g. image loading). Maybe some snippet-solution is possible? Should I care about Nyquist frequency?

**Tags:** image-processing, noise, sampling

> **Comments:**
> **username_1**: Using a paint program that has a "nearest neighbor" resize mode would give you a quick approximation, though it may not select the exact same rows/columns as your code. I think it would be pretty easy to prototype in Python using [pillow](https://python-pillow.org/) for image manipulation.  
> **username_2**: *"I cannot find any examples of how such downscaling will behave."*   Did you ever play old 3D games like Doom and see the hideous aliasing artefacts on walls/objects in the distance? That's what it will be like.  
> **username_3**: Note that PAL and NTSC are a 4:3 aspect ratio (despite NTSC seeming like 3:2  - it has non-square pixels at 720x480). 32x16 is 2:1, so you will either be stretching the video, or pillar boxing it. In my opinion, pillar box is far better, but given the abstractness of your description, maybe you'd prefer to stretch it?  

---

## 2 answers

### Answer by username_2 on 2017-01-13. Score: 1 | Accepted answer

***"Downscaling by skipping rows and columns – any example images?"***

You asked for example images: The following is a sequence of 50 frames from a well known (and hopefully freely available) sequence, subsampled as you suggested.

I think you might find simply subsampling/decimating to be a bit too noisy.

Are you sure you can't at least do some box filtering?

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

> **Comments:**
> **username_0**: I now established that I will use stm32f767 which – not looked myself yet – has DSP commands. I might do some computations after all, clock is 216 MHz and DMA is said to be flexible. I will read ADV7280 output clocked at 54 MHz, though (interlace -> progressive enabled).  

---

### Answer by username_4 on 2017-01-13. Score: 1

A basic nearest neighbour scale function would work like so. Here I also use 24:8 fixed point arithmetic to make it more micro friendly.

```
const int originalWidth = 320, originalHeight = 240;
int targetWidth = 50, targetHeight = 50;

char *pSource = sourceBuffer; 
char *pDest = destBuffer;    // you can use RGB instead of char

int yStep = (originalWidth << 8) / targetWidth;
int xStep = (originalHeight << 8) / targetHeight;

for(int y = 0, sampleY = 0; y < targetHeight; y++, sampleY += yStep) {
    // Point to start of scaled Y source line
    char *pSourceLine = pSource + ((sampleY >> 8) * originalWidth);

    // Output the line, scaling only in X (we already know scaled-Y)
    for(int x = 0, sampleX = 0; x < targetWidth; x++, sampleX += xStep)
        *pDest++ = pSourceLine[sampleX >> 8];
}

```

This will also work to scale image up as well as down, it should work on any input vs output size.


---

