matlab程序minfilt2,程序运行出错,求指教!

博主在MATLAB2014a中使用minfilt2函数处理图像时遇到错误,函数在调用vanherk算法时提示未找到与'double'类型输入参数相对应的函数。此错误可能由于MATLAB版本不支持或缺少相关函数导致。文章附带了minfilt2函数源代码,并请求帮助找出问题所在。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这段程序的最后一行调用了一个minfilt2函数,但是每次运行到这里就出错,我的MATLAB版本是2014a,师兄的MATLAB是MATLAB7版本,他的就可以运行,请各位同学老师帮忙看看,我这是哪里出现错误了,错误在下边,我贴出来了。

clc;

clear all;

tic

img_name=imread('ny1.bmp');

% 原始图像

I=double(img_name)/255;

figure,imshow(I)

% 获取图像大小

[h,w,c]=size(I);

win_size = 7;

img_size=w*h;

win_dark=zeros(h,w);

k=0.01;

w0=0.95;

t0=0.1;

for y=1:h

for x=1:w

win_dark(y,x) = min(I(y,x,:));

end

end

figure,imshow(win_dark), title('Min(R,G,B)');

win_dark1 = minfilt2(win_dark, [win_size,win_size]);

运行到这里之后,MATLAB提示错误如下:

未定义与 'double' 类型的输入参数相对应的函数 'vanherk'。

出错 minfilt2 (line 29)

Y = vanherk(X,S(1),'min',shape);

出错 sunxiaoming1 (line 26)

win_dark1 = minfilt2(win_dark, [win_size,win_size]);

minfilt2的程序如下:

function Y = minfilt2(X,varargin)

%  MINFILT2    Two-dimensional min filter

%

%     Y = MINFILT2(X,[M N]) performs two-dimensional minimum

%     filtering on the image X using an M-by-N window. The result

%     Y contains the minimun value in the M-by-N neighborhood around

%     each pixel in the original image.

%     This function uses the van Herk algorithm for min filters.

%

%     Y = MINFILT2(X,M) is the same as Y = MINFILT2(X,[M M])

%

%     Y = MINFILT2(X) uses a 3-by-3 neighborhood.

%

%     Y = MINFILT2(..., 'shape') returns a subsection of the 2D

%     filtering specified by 'shape' :

%        'full'  - Returns the full filtering result,

%        'same'  - (default) Returns the central filter area that is the

%                   same size as X,

%        'valid' - Returns only the area where no filter elements are outside

%                  the image.

%

%     See also : MAXFILT2, VANHERK

%

% Initialization

[S, shape] = parse_inputs(varargin{:});

% filtering

Y = vanherk(X,S(1),'min',shape);

Y = vanherk(Y,S(2),'min','col',shape);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [S, shape] = parse_inputs(varargin)

shape = 'same';

flag = [0 0]; % size shape

for i = 1 : nargin

t = varargin{i};

if strcmp(t,'full') & flag(2) == 0

shape = 'full';

flag(2) = 1;

elseif strcmp(t,'same') & flag(2) == 0

shape = 'same';

flag(2) = 1;

elseif strcmp(t,'valid') & flag(2) == 0

shape = 'valid';

flag(2) = 1;

elseif flag(1) == 0

S = t;

flag(1) = 1;

else

error(['Too many / Unkown parameter : ' t ])

end

end

if flag(1) == 0

S = [3 3];

end

if length(S) == 1;

S(2) = S(1);

end

if length(S) ~= 2

error('Wrong window size parameter.')

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值