convolution of the corner pixel

2 ビュー (過去 30 日間)
Jim
Jim 2011 年 9 月 23 日
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

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 9 月 23 日
>> 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

その他の回答 (2 件)

Image Analyst
Image Analyst 2011 年 9 月 23 日
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 2011 年 9 月 23 日
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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by