Sign in to follow this  
vpk

image processing

Recommended Posts

Are you trying this on a bitmap, or on OpenGL/DirectX textures?

Most image processing filters are working by looping through all pixels. For each pixel (from the original image), you look at the neighbour pixels. For example, check the 8 surrounding pixels. Ussually when you adjust the "strength" or "size" in a paint program, you adjust the box size around the pixel.

With neighbour pixels and the center pixel(the one you are currently on), you can do all kind of tricks. Alot of filters are working with a "kernel" This kernel is a 2D matrix with values
http://images.google.nl/images?hl=nl&q=gaussian+kernel&gbv=2
You multiply the kernel values with the neighbour and central pixels, sum all results, and divide with the count of pixels you have been using (9 pixels, in case you use a 3x3 kernel) to get the average. This result is stored in a new texture.

for x:=1 to originalImage.width do
for y:=1 to originalImage.height do
newPixel.rgb = filterX( x,y, originalImage );
newImage.pixels[x,y] = newPixel.rgb;


I don't know the variance effect, but as for the mean, you pick the center pixel + neighbours. Let's say you use a small 3x3 area = 9 pixels. You'll have to order these values in an array. I'm not sure what's the best way to order though. You could calculate the luminance (1 single value) per pixel, and order on luminance -> array[0] = darkest pixel, array[MAX_SIZE] = brightes_pixel.

But you can also order per channel. Make 3 array's, 1 for red, 1 green, and 1 for blue. For each pixel, you extract the red,green and blue color. Place the red value in the red array, green in green array, etc.

In the end, you take the mid values from the array(s)

// In case you order the 3 color channels appart:
result.r = red_Array[ ARRAY_SIZE / 2 ];
result.g = green_Array[ARRAY_SIZE / 2 ];
result.b = blue_Array[ ARRAY_SIZE / 2 ];


Greetings,
Rick

Share this post


Link to post
Share on other sites
i am trying to calculate the mean and variance of a gray scale image..

u mean to say the mean of an image is calculated on each pixel basis??

Share this post


Link to post
Share on other sites
Depends. If you want to apply a mean filter (mainly used to remove noise from an image), you need to do it per pixel indeed. If you are using gray-scale images, the routine stays the same, although you don't have to use 3 color channels. Just order the pixel/neighbours on luminance.

However, if you want 1 single mean value over the entire image, you can forget about what I said with kernels. The only thing you'll have to do in that case, is to order ALL the pixels in 1 big array. Loop through all pixels, and place them on the right position inside that big array. The overall mean value is the value at array[ ARRAY_SIZE / 2 ], where ARRAY_SIZE = image.width * image.height.

Greetings,
Rick

Share this post


Link to post
Share on other sites
Hi,

what spek means is the median not the mean. The mean is calculated as in any other domain by summing over all pixels and dividing by the number of pixels.
For variance do the same except that you sum over (image_value - mean value)^2.

Hope this helps.

PS.: you can to the variance and the mean calculation in one go if you look up the formulas.

Share this post


Link to post
Share on other sites
Shoot. My technical english is crap. That reminds me I'll have to replace "mean" with "median" in some other applications I recently made as well. Sorry for confusing you guys :)

Rick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this