Skip to content

Instantly share code, notes, and snippets.

@r-malon
Last active March 23, 2020 18:37
Show Gist options
  • Save r-malon/2ada8560e614bfb595e80ecf0cef57a1 to your computer and use it in GitHub Desktop.
Save r-malon/2ada8560e614bfb595e80ecf0cef57a1 to your computer and use it in GitHub Desktop.
Pseudo-code for my demosaicing algorithms
function demosaic(img)
{
largura, altura = img.tamanho
R, G, B = 0, 1, 2
for (int x = 0; x < largura; x++)
{
for (int y = 0; y < altura; y++)
{
red = ( img[x - 1, y - 1][R] + img[x + 1, y + 1][R] ) / 2
green = ( img[x - 1, y - 1][G] + img[x + 1, y + 1][G] ) / 2
blue = ( img[x - 1, y - 1][B] + img[x + 1, y + 1][B] ) / 2
if (x % 2 == 0 and y % 2 == 0) // se ambas coordenadas forem pares
{
img[x, y] = (red, green, img[x, y][B])
}
else if (x % 2 != 0 and y % 2 != 0)
{
img[x, y] = (img[x, y][R], green, blue)
}
else {
img[x, y] = (red, img[x, y][G], blue)
}
}
}
}
function demosaic(img)
{
largura, altura = img.tamanho
R, G, B = 0, 1, 2
for (int x = 0; x < largura; x++)
{
for (int y = 0; y < altura; y++)
{
green = (img[x, y + 1][G] + img[x + 1, y][G]) / 2
if (x % 2 == 0 and y % 2 == 0)
{
red = img[x + 1, y + 1][R]
img[x, y] = (red, green, img[x, y][B])
}
else if (x % 2 != 0 and y % 2 != 0)
{
blue = img[x + 1, y + 1][B]
img[x, y] = (img[x, y][R], green, blue)
}
else {
red = img[x, y + 1][R]
blue = img[x + 1, y][B]
img[x, y] = (red, img[x, y][G], blue)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment