Jump to content
  • Advertisement
Sign in to follow this  
ff8

Matrix Filter ?

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ,

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 ,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ,

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!