我将特定大小和方向的Gabor滤镜应用于灰度图像 . 所以我通过使用2-D卷积“conv2”获得新的滤波图像 . 我看到有些人试图从过滤后的图像中删除边框,换句话说,要取消过滤后的图像 . 这些边界是什么?
例如:
%if length(amount==1) , unpad equal on each side.
%if length(amount==2) , first amount is left right, second amount is up down.
%if length(amount==4) , then [left top right bottom].
switch (length(amount))
case 1
sx=size(i,2) - 2 * amount; % i is the filtered image
sy=size(i,1) - 2 * amount;
left=amount + 1;
right=size(i,2) - amount;
top=amount + 1;
bottom = size(i,1) - amount;
case 2
sx=size(i,2) - 2 * amount(1);
sy=size(i,1) - 2 * amount(2);
left=amount(1) + 1;
right = size(i,2) - amount(2);
top= amount(2) +1;
bottom = size(i,1) - amount(2);
case 4
sx=size(i,2) - (amount(1) + amount(3));
sy= size(i,1) - (amount(2) + amount(4));
left = amount(1) + 1;
right = size(i,2) - amount(3);
top = amount(2) + 1;
bottom = size(i,1) - amount(4);
otherwise
error('illegal unpad amount\n');
end
我不明白这个代码,左,右,上,下是什么?它们与sx和sy有什么区别?请有人帮助我,并详细解释这个代码中发生的事情 .
1 回答
在线性卷积(由
conv2
实现)中,经过滤波的图像在边缘处获得一些边距,因为卷积的工作方式是一样的.2426504_ . 此功能删除这些边距(可能获取图像的原始大小,取决于amount
的值),而:amount
- 保证金的大小 .sx
- 新的列数 .sy
- 新行数 .left
- 新图像开始的列号 .right
- 新图像结束的列号 .top
- 新图像开始的行号 .bottom
- 新图像结束的行号 .所以,您可以从中获取新图像:
NewI=i(top:bottom,left:right);
EDIT :(对于评论的问题)
假设您想要从每一侧重新发送
amount
列,例如5.因此,您删除的总列数为10.因此,新列数是原始数字(size(i,2)
)减去10(2*amount
) . 行号相同 .因为要从左侧删除5列,所以剩下的第一列是第6列,所以现在左边框将是6(
amount+1
) . 这也是其余的想法(右,上,下)