DSPRelated.com
Forums

masks: 2 in a row?

Started by Unknown March 5, 2009
Hi all

I'm working on masks (prewitt, sobel, mean, etc) with the CImg library. Right now I can apply masks quite well, and I have a question about the next "natural" step.

If I want to apply two masks consecutively, let's say mean and prewitt-x, deffined as:

mean: 1/9, 1/9... 1/9
prewitt-x: 1,1,1|0,0,0|-1,-1,-1

then I have to apply first the mean mask to my initial image, img , resulting on img_mean, and then, I have to apply the prewitt-x filter to img_mean, resulting in img_mean_prewit.

My question is, does exist a matrix, let's call it mean-prewitt-x, such as its application on an image is equivalent to apply consecutively mean and prewitt masks?

My first idea is that such matrix could be something like

mean-prewitt-x: 1/9,1/9,1/9|0,0,0|-1/9,-1/9,-1/9

but it's clear it can't be that easy because this "method" is commutative, while applying filters on an image isn't.

Any idea about this? Or maybe just a keyword that helped to search about this topic on google...

Thanks in advance
Hi All,

The resultant filter will be convoultion of mean and prewitt filter.

Get the convolution of mean and prewitt filter.

Use that filter on the image to get mean_prewitt_x.

Is the doubt cleared.

Regards
Naresh
On 3/5/09, Emilio Dz wrote:
> Hi all
>
> I'm working on masks (prewitt, sobel, mean, etc) with the CImg library.
> Right now I can apply masks quite well, and I have a question about the next
> "natural" step.
>
> If I want to apply two masks consecutively, let's say mean and prewitt-x,
> deffined as:
>
> mean: 1/9, 1/9... 1/9
> prewitt-x: 1,1,1|0,0,0|-1,-1,-1
>
> then I have to apply first the mean mask to my initial image, img ,
> resulting on img_mean, and then, I have to apply the prewitt-x filter to
> img_mean, resulting in img_mean_prewit.
>
> My question is, does exist a matrix, let's call it mean-prewitt-x, such as
> its application on an image is equivalent to apply consecutively mean and
> prewitt masks?
>
> My first idea is that such matrix could be something like
>
> mean-prewitt-x: 1/9,1/9,1/9|0,0,0|-1/9,-1/9,-1/9
>
> but it's clear it can't be that easy because this "method" is commutative,
> while applying filters on an image isn't.
>
> Any idea about this? Or maybe just a keyword that helped to search about
> this topic on google...
>
> Thanks in advance
>
>
>

--
***********************************************
Naresh Reddy Yarram
Research Associate
KPIT Cummins Infosystems Ltd

**********************************************

_____________________________________
Convolution is commutative. First convolve the mean mask with the prewitt mask. Let's call the resultto be 'mean-prewitt-convolved'. Now, apply mean-prewitt-convolved mask on your image. It should work!

Regards,

Anuj

________________________________
From: Emilio Dz
To: i...
Sent: Thursday, 5 March, 2009 7:47:20 PM
Subject: [imagedsp] masks: 2 in a row?

Hi all

I'm working on masks (prewitt, sobel, mean, etc) with the CImg library. Right now I can apply masks quite well, and I have a question about the next "natural" step.

If I want to apply two masks consecutively, let's say mean and prewitt-x, deffined as:

mean: 1/9, 1/9... 1/9
prewitt-x: 1,1,1|0,0,0| -1,-1,-1

then I have to apply first the mean mask to my initial image, img , resulting on img_mean, and then, I have to apply the prewitt-x filter to img_mean, resulting in img_mean_prewit.

My question is, does exist a matrix, let's call it mean-prewitt- x, such as its application on an image is equivalent to apply consecutively mean and prewitt masks?

My first idea is that such matrix could be something like

mean-prewitt- x: 1/9,1/9,1/9| 0,0,0|-1/ 9,-1/9,-1/ 9

but it's clear it can't be that easy because this "method" is commutative, while applying filters on an image isn't.

Any idea about this? Or maybe just a keyword that helped to search about this topic on google...

Thanks in advance

_____________________________________
Hi,

yes, its possible the mask u need is:
G=mean*prewitt (* = convolution)
G = 1/9 . [
-1 -2 -3 -2 -1
-1 -2 -3 -2 -1
0 0 0 0 0
1 2 3 2 1
1 2 3 2 1
];

if you find it tough to understand convolution, you can think about it as masking:
zero extend mean to become 5x5
put prewit on it as a mask. you will get the result

but if you are considering speed and computational effitioncy you would better use the original masks. or else if you are considering even more computational efftioncy you can use a row and column matrix as this:
u =[
-0.5000
-0.5000
0
0.5000
0.5000
]

v = [2.0000 4.0000 6.0000 4.0000 2.0000]/9

refer to wikipedia and matlab singl value decomposition (svd) to see how to do this.

so if you first apply u and then v on the image u get the same result.

>Hi all
>
>I'm working on masks (prewitt, sobel, mean, etc) with the CImg library. Right now I can apply masks quite well, and I have a question about the next "natural" step.
>
>If I want to apply two masks consecutively, let's say mean and prewitt-x, deffined as:
>
>mean: 1/9, 1/9... 1/9
>prewitt-x: 1,1,1|0,0,0|-1,-1,-1
>
>then I have to apply first the mean mask to my initial image, img , resulting on img_mean, and then, I have to apply the prewitt-x filter to img_mean, resulting in img_mean_prewit.
>
>My question is, does exist a matrix, let's call it mean-prewitt-x, such as its application on an image is equivalent to apply consecutively mean and prewitt masks?
>
>My first idea is that such matrix could be something like
>
>mean-prewitt-x: 1/9,1/9,1/9|0,0,0|-1/9,-1/9,-1/9
>
>but it's clear it can't be that easy because this "method" is commutative, while applying filters on an image isn't.
>
>Any idea about this? Or maybe just a keyword that helped to search about this topic on google...
>
>Thanks in advance