how do I Average colors in a 3x3 pixel nest.

14 posts in this topic

navajo 0

Ok, this sounds strange, but I've been working on this in two directions, on with hex (what a mess) and one with in Dec. here is what I have currently. I attempt to average the colors in Dec. and come up with an odd skew' to my color average. I believe i need to work in hex and average each RGB segment and rebuild it. But I'm lost on how to even start to do that.

Share this post

Link to post

Share on other sites

navajo 0

Currently I'm working on a test bed system that has problems with color pallets, I would like to grab an areas around a set point and pull in the averages around that point. Not the checksum. As the manual says.

A checksum only allows you to see if "something" has changed in a region - it does not tell you exactly what has changed.

and this is not an average. I need a ratio across the pixel, not a checksum.

Share this post

Link to post

Share on other sites

Paulie 25

so you're trying to add the red green and blue values of a pixel and then divide by three right? that will give you a grey-ish color, though of doing a similar thing in my greyscale filter, but found a better algorithim

what is the purpose of this?

Share this post

Link to post

Share on other sites

PsaltyDS 22

so you're trying to add the red green and blue values of a pixel and then divide by three right? that will give you a grey-ish color, though of doing a similar thing in my greyscale filter, but found a better algorithim

what is the purpose of this?

That wasn't my impression of what was desired. I think he wants to break out the R, G, and B portion of the color, get the average of each primary color, and reassemble that to an average color for the 3x3 grid. This is what my function is attempting to do, anyway.

Share this post

Link to post

Share on other sites

Paulie 25

That wasn't my impression of what was desired. I think he wants to break out the R, G, and B portion of the color, get the average of each primary color, and reassemble that to an average color for the 3x3 grid. This is what my function is attempting to do, anyway.

Okay, now I'm REALLY confused

Is he looking for

_ColorGetRed()

_ColorGetGreen()

_ColorGetBlue()

the "Average" color for ANY RGB value is going to be either black, grey, or white

set those sliders to any numbers you want, the average the decimal values, and set them to the result, and you will see that it turns out gray

Well, we need to hear from navajo to see if I've misunderstood him, but...

Assume a block of 9 pixels (3x3) that are the following colors coordinates are relative to the center pixel:

-1,-1 = 0xFF0000 ; Red

0, -1 = 0x00FF00 ; Green

1, -1 = 0xFFFF00 ; Red/Green

-1,0 = 0xFF0000 ; Red

0, 0 = 0x00FF00 ; Green

1, 0 = 0xFFFF00 ; Red/Green

-1,1 = 0xFF0000 ; Red

0, 1 = 0x00FF00 ; Green

1, 1 = 0xFFFF00 ; Red/Green

My script breaks each pixel's color into R, G, and B values and adds all the Reds together, all the Greens together, and all the Blues together. Then it divides each by 9, giving the average redness, average greeness, and average blueness. Lastly those three averaged tints are recombined into a single average RGB color.

-1,-1 = 0xFF0000 ; Red = FF, 00, 00

0, -1 = 0x00FF00 ; Green = 00, FF, 00

1, -1 = 0xFFFF00 ; Red/Green = FF, FF, 00

-1,0 = 0xFF0000 ; Red = FF, 00, 00

0, 0 = 0x00FF00 ; Green = 00, FF, 00

1, 0 = 0xFFFF00 ; Red/Green = FF, FF, 00

-1,1 = 0xFF0000 ; Red = FF, 00, 00

0, 1 = 0x00FF00 ; Green = 00, FF, 00

1, 1 = 0xFFFF00 ; Red/Green = FF, FF, 00

Add up the Reds:

FF + 00 + FF + 00 + FF + 00 + FF + 00 + FF = 0x4FB

Add up the Greens:

00 + FF + 00 + FF + 00 + FF + 00 + FF + 00 = 0x3FC

Add up the Blues:

0 + 0 + 0+ 0 + 0+ 0 + 0+ 0 + 0 = 0

Average each color (separately):

0x4FB / 9 = 0x8D ; Average redness

0x3FC / 9 = 0x71 ; Average greeness

0 / 9 = 0 ; Average blueness

Assemble the average component colors into a single average color:

RGB = 8D, 71, 00 = 0x8D7100

So the average color of those 9 pixels is 0x8D7100. At least, as I understand it, and my code above calculates it. What are the other theories?

Share this post

Link to post

Share on other sites

Paulie 25

Well, we need to hear from navajo to see if I've misunderstood him, but...

Assume a block of 9 pixels (3x3) that are the following colors coordinates are relative to the center pixel:

-1,-1 = 0xFF0000 ; Red

0, -1 = 0x00FF00 ; Green

1, -1 = 0xFFFF00 ; Red/Green

-1,0 = 0xFF0000 ; Red

0, 0 = 0x00FF00 ; Green

1, 0 = 0xFFFF00 ; Red/Green

-1,1 = 0xFF0000 ; Red

0, 1 = 0x00FF00 ; Green

1, 1 = 0xFFFF00 ; Red/Green

My script breaks each pixel's color into R, G, and B values and adds all the Reds together, all the Greens together, and all the Blues together. Then it divides each by 9, giving the average redness, average greeness, and average blueness. Lastly those three averaged tints are recombined into a single average RGB color.

-1,-1 = 0xFF0000 ; Red = FF, 00, 00

0, -1 = 0x00FF00 ; Green = 00, FF, 00

1, -1 = 0xFFFF00 ; Red/Green = FF, FF, 00

-1,0 = 0xFF0000 ; Red = FF, 00, 00

0, 0 = 0x00FF00 ; Green = 00, FF, 00

1, 0 = 0xFFFF00 ; Red/Green = FF, FF, 00

-1,1 = 0xFF0000 ; Red = FF, 00, 00

0, 1 = 0x00FF00 ; Green = 00, FF, 00

1, 1 = 0xFFFF00 ; Red/Green = FF, FF, 00

Add up the Reds:

FF + 00 + FF + 00 + FF + 00 + FF + 00 + FF = 0x4FB

Add up the Greens:

00 + FF + 00 + FF + 00 + FF + 00 + FF + 00 = 0x3FC

Add up the Blues:

0 + 0 + 0+ 0 + 0+ 0 + 0+ 0 + 0 = 0

Average each color (separately):

0x4FB / 9 = 0x8D ; Average redness

0x3FC / 9 = 0x71 ; Average greeness

0 / 9 = 0 ; Average blueness

Assemble the average component colors into a single average color:

RGB = 8D, 71, 00 = 0x8D7100

So the average color of those 9 pixels is 0x8D7100. At least, as I understand it, and my code above calculates it. What are the other theories?

Share this post

Link to post

Share on other sites

navajo 0

Yes, thats exactly what I was looking to do, I just could not figure out how to pull out the colors, thank you!

That wasn't my impression of what was desired. I think he wants to break out the R, G, and B portion of the color, get the average of each primary color, and reassemble that to an average color for the 3x3 grid. This is what my function is attempting to do, anyway.