Paper outcome above. I’m not going anything this complicated (beziers) yet, but just a simple working prototype of the diffusion part.
The broad idea with Diffusion Curves is you specify some pixels in a canvas (such as the colour bezier lines in (b) above) and then spread the colours throughout the rest of the canvas by, for each pixel, averaging the four adjacent (non-diagonal) pixels (i.e. up, down, left, right). This is repeated until all the pixels are filled and the colours stabilise.
With that brief introduction, my question concerns section 3.2.2 of this paper.
There’s a lot maths leading up to this part, but the diffusion algorithm seems to boil down to something quite simple:
So, if a pixel (at location i,j) is user-defined (alpha-mask > 0), you don’t average it with other pixels – rather, you keep the user-defined colour. Otherwise, you average a pixel with it’s neighboring pixels.
But it’s the formula of this averaging part that is a bit confusing:
divwij is first defined as the green region minus 4Iij. However, in the next part (which tells us how to calculate a pixel), divwij is subtracted from the green region, essentially cancelling out each value, leaving only positive 4Iij – this has to be wrong, so my question is: what’s going on here?
Another point of confusion: straight after that divwij is (re)defined as this:
I’m not sure whether I’m meant to do anything with that😁.
Appendix: the loop I’ve developed so far simply averages the neighboring pixels and kinda works, but it’s not quite implementing the paper.
for (int x = 1; x < width - 1; x++) { // -1 edge buffer
for (int y = 1; y < height - 1; y++) {
if (alphaMask[x][y] == 1) { // dont diffuse user-defined pixels
pixels[x + width * y] = composeclr(canvas[x][y]); // but still copy user-defined pixel into pixels[]
continue;
}
canvas[x][y][0] = // R component
0.25f * canvas[x - 1][y][0] +
0.25f * canvas[x + 1][y][0] +
0.25f * canvas[x][y - 1][0] +
0.25f * canvas[x][y + 1][0];
canvas[x][y][1] = // B component
0.25f * canvas[x - 1][y][1] +
0.25f * canvas[x + 1][y][1] +
0.25f * canvas[x][y - 1][1] +
0.25f * canvas[x][y + 1][1];
canvas[x][y][2] = // B component
0.25f * canvas[x - 1][y][2] +
0.25f * canvas[x + 1][y][2] +
0.25f * canvas[x][y - 1][2] +
0.25f * canvas[x][y + 1][2];
pixels[x + width * y] = composeclr(canvas[x][y]); // write int clr into Processing pixels[]
}
Input: 2000 random-coloured pixels
Input: One-pixel high pink and blue lines