设计我自己的2D滤镜--matlab [英] design my own 2d filter--matlab

查看:84
本文介绍了设计我自己的2D滤镜--matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以定义自己的2D过滤器.假设有一个矩阵A,我想将A的每个元素分配给它的8个邻居的最大值.例如:

I'm wondering is there a way to define my own 2d filter. Assuming there is a matrix A, I'd like to assign every element of A to the maximum value of its 8 neighbors. For example:

A = [1 2 3 4 5
     6 7 8 9 10
     -1 3 4 8 13
     4 2 0 9 1]

过滤后:

A = [1 2 3 4 5
     6 8 9 10 10
     -1 8 9 13 13
     4 2 0 9 1]

谢谢

推荐答案

您可以使用nlfilter创建一个任意过滤器,例如这里.就您而言:

You can create an arbitrary filter with nlfilter, an example here. In your case:

fun = @(x) max(x(:)),
B = nlfilter(YourImage,[3 3],fun);

如果要排除中心像素,请将fun替换为:

In the case that you want to exclude the center pixel, replace fun by something like:

fun=@(x) max([x(1:3, 1)' x(1,2) x(3,2) x(1:3,3)'])

这篇关于设计我自己的2D滤镜--matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆