Skip to main content
GameDev.net gamedev.net
🔒 Locked

Matrix Filter ?

Started by ff8 Sep 23, 2005 at 6:16 AM 7 replies 1.5k views
Original Post
ff8
ff8
Hello! , how are u guys ? i have a question about appling Matrix Filter on RGB array . what i got it is : let's say this an image array 100 | 50 | 100 100 |100| 50 100 | 50 | 100 and this is Matrix filter : 0 | 0 | 0 0 | 1 | 0 0 | 0 | 0 when we apply it on the bold 100 the result will be (0*100) + (0*50) + ... = 100 correct ? ok if it is correct how can i apply it in RGB image array ? cya ,
PixelPhil
PixelPhil
I think what you are trying to do is a convolution by a kernel matrix (a bit of vocabulary to google here).
To apply it on rgb images, just perform the same computaion on the three componenents channels. As if you where doing what you wrote on three distinct grayscale images.

The kernel you show as an example is the identity kernel, so it will just do nothing.

a better example would be:

|0.09 0.11 0.09||0.11 0.20 0.11| -> some kind of blur|0.09 0.11 0.09|


note that the sum of the elements of the kernel is 1.0 to avoid energy loss (or gain).

I hope this helps,

Phil
ff8
ff8
hey ^^
ok lets say we have Image array Img[3*3][3] and kernel matrix Km[3*3]
Img [3*3]{3]:
100,250,50 | 125,255,10 | 25,100,88
0 ,100,12 | 20,54,120 | 100,100,100
255,255,255| 50,10,55 | 1,255,0
Km[3*3]:
0 | 0 | 0
0 | 1 | 0
0 | 0 | 0
ok now how can i apply kernel matrix on the bold pixel ?
cya ,
Kalidor
Kalidor
Quote:
Original post by ff8
hey ^^
ok lets say we have Image array Img[3*3][3] and kernel matrix Km[3*3]
Img [3*3]{3]:
100,250,50 | 125,255,10 | 25,100,88
0 ,100,12 | 20,54,120 | 100,100,100
255,255,255| 50,10,55 | 1,255,0
Km[3*3]:
0 | 0 | 0
0 | 1 | 0
0 | 0 | 0
ok now how can i apply kernel matrix on the bold pixel ?
cya ,
It's just as PixelPhil said, it's applied just like it is to a grayscale image except you're multiplying three channels instead of one. In this particular case it would come out to
(0*...) + (0*...) + ... + (1 * (20, 54, 120)) + ...   = 1 * (20, 54, 120)   = (1*20, 1*54, 1*120)   = (20, 54, 120)
Just post if you need anymore clarification.
ff8
ff8
thank you both ^^ i have last question ...
let's say the first pixel of the img[0] how can i apply the kernel matrix .. ?
cya ,
PixelPhil
PixelPhil
You can assume a fixed border color but then ou would have some of this color appearing in you final image.

The cleanest way is to clamp your lookup coordinates between 0 and size-1. this as the effect of propagating the color of the border pixel outside of the matrix.

basically if you need image[-1, 2] take image[0, 2]

example:

      |1 2 3|                |0.3 0   0.1|image |4 5 6|  filter kernel |0   0.3 0  |      |7 8 9|                |0   0   0.3|


image[0,0] = 1 here

the convolution of that pixel is (ignoring the 0s):

0.3 * image[-1,-1] + 0.1 * image[2,-1] + 0.3 * image[0,0] + 0.3 * image[1,1]

because your image is not defined in aras with negative coordinates you transform this to:

0.3 * image[0,0] + 0.1 * image[2,0] + 0.3 * image[0,0] + 0.3 * image[1,1]
= 0.3 * 1 + 0.1 * 3 + 0.3 * 1 + 0.3 * 5
= 2.4

if you hade image[x, 3] you would take image[x, 2] too...

Phil
ff8
ff8
ah i got it ^_^ thank you vm ^^
cya,
UltimaX
UltimaX
Here is a good page that I found as a good resource.
ff8
ff8
thank you UltimaX for the link , ^^
i have my last question
ok when i apply kernel matric on the RGB image array let's say this :
.5*(100,255,0) + .1*(255,25,50) + ....=
(.5*100,.5*255,.5*0)+(.1*255,.1*25,.1*50)+...=
the result will be
[(R1+R2+R3+....),(G1+G2+G3+...),(B1+B2+B3+....)] is this correct ??

cya ,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.