Effacer les filtres
Effacer les filtres

convolution of the corner pixel

3 vues (au cours des 30 derniers jours)
Jim
Jim le 23 Sep 2011
Hi,
I am using 2-D image here and I used this command
conv2(Img, [1,1,1; 1,0,1; 1,1,1] / 8, 'same')
Example:
image1 = [1 2 3 3 0;3 4 1 0 1 ;2 3 0 7 5;4 0 2 5 1;0 3 1 6 4];
image2=conv2(image1, [1,1,1;1,0,1;1,1,1] / 8, 'same');
I got result like this:
1.125000 1.5000 1.25000 0.625000 0.5000 1.5000 1.875000 2.75000 2.5000 1.875000 1.75000 2 2.75000 1.875000 1.75000 1 1.875000 3.125000 3.25000 3.375000 0.87500 0.875000 2 1.62500 1.5000
By using conv2 I think it will give the average of the surrounding pixels
In image1 3rd row 3rd column 0 is replaced by the average of the surrounding pixels like (4+1+0+3+7+0+2+5)/8=2.75000
What about the corner pixel i.e 1st row and 1st column? 1 is replaced by 1.25000
How this 1.25000 came
How it is taking the average of the corner pixel
Can anyone suggest something about this
Thanks in advance

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 23 Sep 2011
>> image2_11 = [0 0 0;0 1 2;0 3 4]
image2_11 =
0 0 0
0 1 2
0 3 4
>>L = true(3);L(2,2)=false
L =
1 1 1
1 0 1
1 1 1
>> image2_11 = image2_11.*L
ans =
0 0 0
0 0 2
0 3 4
>>image2_11 = sum(image2_11(:))/8
image2_11 = 1.125

Plus de réponses (2)

Image Analyst
Image Analyst le 23 Sep 2011
When the lower right corner of the kernel just barely overlaps your image, only the "1" in the lower right of the kernel overlaps only the "1" of your image. (1*1) / 8 = 0.125. Not sure what to suggest. That's how convolution works. You can crop it away if you want using the 'same' option, or you can program up various other ways to handle the edge effects.

Bjorn Gustavsson
Bjorn Gustavsson le 23 Sep 2011
If you have access to the image processing toolbox you can use imfilter (that also does linear filtering). Imfilter have some extra luxurious handling of edges - 'replicate', 'symmetric' (maybe even 'circular'?). These might do what you want for edges and corners. If you haven't got the IP-toolbox, I have to say as Image Analyst: you'll have to write it yourself.
HTH

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by