Matlab 获取图像大小时没有足够的输入参数

Matlab 获取图像大小时没有足够的输入参数,matlab,Matlab,我尝试做手指静脉特征提取我有两个文件 我犯了这个错误 第二个文件中的(第29行) [img_h, img_w] = size(img); function [region, edges] = lee_region(img, mask_h, mask_w) % Localise the finger region % Parameters: % img - Input vascular image % mask_h - Height of the mask % mask_w - W

我尝试做手指静脉特征提取我有两个文件 我犯了这个错误 第二个文件中的(第29行)

[img_h, img_w] = size(img);
function [region, edges] = lee_region(img, mask_h, mask_w)
% Localise the finger region

% Parameters:
%  img    - Input vascular image
%  mask_h - Height of the mask
%  mask_w - Width of the mask

% Returns:
%  region - Binary mask indicating the finger region
%  edges  - Matrix containing two rows, first row corresponds to the 
%           y-positions of the upper finger edge and the second row
%           corresponds to the y-positions of the lower finger edge.

% Reference:
% Finger vein recognition using minutia-based alignment and local binary
%   pattern-based feature extraction
% E.C. Lee, H.C. Lee and K.R. Park
% International Journal of Imaging Systems and Technology
%   Volume 19, Issue 3, September 2009, Pages 175-178   
% doi: 10.1002/ima.20193

% Author:  Bram Ton <b.t.ton@alumnus.utwente.nl>
% Date:    20th March 2012
% License: Simplified BSD License


[img_h, img_w] = size(img);

% Determine lower half starting point
if mod(img_h,2) == 0
    half_img_h = img_h/2 + 1;
else
    half_img_h = ceil(img_h/2);
end

% Construct mask for filtering
mask = zeros(mask_h,mask_w);
mask(1:mask_h/2,:) = -1;
mask(mask_h/2 + 1:end,:) = 1;

% Filter image using mask
img_filt = imfilter(img, mask,'replicate'); 
%figure; imshow(img_filt)

% Upper part of filtred image
img_filt_up = img_filt(1:floor(img_h/2),:);
[~, y_up] = max(img_filt_up); 

% Lower part of filtred image
img_filt_lo = img_filt(half_img_h:end,:);
[~,y_lo] = min(img_filt_lo);

% Fill region between upper and lower edges
region = zeros(size(img));
for i=1:img_w
    region(y_up(i):y_lo(i)+size(img_filt_lo,1), i) = 1;
end

% Save y-position of finger edges
edges = zeros(2,img_w);
edges(1,:) = y_up;
edges(2,:) = round(y_lo + size(img_filt_lo,1));
输入参数不足。 首先

这是第二个文件

[img_h, img_w] = size(img);
function [region, edges] = lee_region(img, mask_h, mask_w)
% Localise the finger region

% Parameters:
%  img    - Input vascular image
%  mask_h - Height of the mask
%  mask_w - Width of the mask

% Returns:
%  region - Binary mask indicating the finger region
%  edges  - Matrix containing two rows, first row corresponds to the 
%           y-positions of the upper finger edge and the second row
%           corresponds to the y-positions of the lower finger edge.

% Reference:
% Finger vein recognition using minutia-based alignment and local binary
%   pattern-based feature extraction
% E.C. Lee, H.C. Lee and K.R. Park
% International Journal of Imaging Systems and Technology
%   Volume 19, Issue 3, September 2009, Pages 175-178   
% doi: 10.1002/ima.20193

% Author:  Bram Ton <b.t.ton@alumnus.utwente.nl>
% Date:    20th March 2012
% License: Simplified BSD License


[img_h, img_w] = size(img);

% Determine lower half starting point
if mod(img_h,2) == 0
    half_img_h = img_h/2 + 1;
else
    half_img_h = ceil(img_h/2);
end

% Construct mask for filtering
mask = zeros(mask_h,mask_w);
mask(1:mask_h/2,:) = -1;
mask(mask_h/2 + 1:end,:) = 1;

% Filter image using mask
img_filt = imfilter(img, mask,'replicate'); 
%figure; imshow(img_filt)

% Upper part of filtred image
img_filt_up = img_filt(1:floor(img_h/2),:);
[~, y_up] = max(img_filt_up); 

% Lower part of filtred image
img_filt_lo = img_filt(half_img_h:end,:);
[~,y_lo] = min(img_filt_lo);

% Fill region between upper and lower edges
region = zeros(size(img));
for i=1:img_w
    region(y_up(i):y_lo(i)+size(img_filt_lo,1), i) = 1;
end

% Save y-position of finger edges
edges = zeros(2,img_w);
edges(1,:) = y_up;
edges(2,:) = round(y_lo + size(img_filt_lo,1));
函数[region,edges]=lee_区域(img,mask_h,mask_w)
%定位手指区域
%参数:
%输入血管图像
%遮罩h-遮罩的高度
%遮罩w-遮罩的宽度
%返回:
%区域-指示手指区域的二进制掩码
%边-包含两行的矩阵,第一行对应于
%上指边和第二行的y位置
%对应于下指边的y位置。
%参考:
%基于细节点对齐和局部二值化的手指静脉识别
%基于模式的特征提取
%E.C.Lee、H.C.Lee和K.R.Park
%国际成像系统与技术杂志
%第19卷第3期,2009年9月,第175-178页
%内政部:10.1002/ima.20193
%作者:布拉姆·顿
%日期:2012年3月20日
%许可证:简化的BSD许可证
[img_h,img_w]=尺寸(img);
%确定下半部分的起点
如果mod(img_h,2)==0
半模高=模高/2+1;
其他的
half_img_h=ceil(img_h/2);
结束
%构造用于过滤的掩码
掩码=零(掩码h,掩码w);
掩码(1:mask_h/2,:)=-1;
遮罩(遮罩h/2+1:end,:)=1;
%用掩模滤除图像
img_filt=imfilter(img,掩码,'replicate');
%数字;imshow(img_filt)
%滤波图像的上半部分
img_filt_up=img_filt(1:楼层(img_h/2),:);
[~,y\u up]=max(img\u filt\u up);
%滤波图像的下半部分
img_filt_lo=img_filt(一半img_h:end,:);
[~,y\u-lo]=min(img\u-filt\u-lo);
%上边缘和下边缘之间的填充区域
区域=零(大小(img));
对于i=1:img_w
区域(y_-up(i):y_-lo(i)+大小(img_-filt_-lo,1),i)=1;
结束
%保存手指边缘的y位置
边=零(2,img_w);
边(1,:)=y_向上;
边(2,:)=圆形(y_-lo+尺寸(img_-filt_-lo,1));

一个可能的原因是您定义了一个名为“size”的函数。如果是这样,请将定义的函数重命名为另一个名称

如果没有,如果您的工作文件夹只有两个文件,如果输入的是彩色图像,那么您将在主文件的
edge\u img(edges(1,:)+size(img,1)*[0:size(img,2)-1])=1行遇到bug,不在第二个文件中。我刚测试过。要解决此错误,需要将所有输入图像(finger.png)转换为灰度。您可以通过以下方式更改主文件:

% This script shows how the finger region and edges can be detected.

img = im2double(imread('finger.png')); % Read image
img = imresize(img, 0.5);              % Downscale image

img = rgb2gray(img);

mask_height=4; % Height of the mask
mask_width=20; % Width of the mask
[fvr, edges] = lee_region(img,mask_height,mask_width);
...
顺便说一下,我使用的matlab版本是MATLAB2012B;而且,如果输入图像是M*N*3,则
[h,w]=size(img)
将返回如下:h=M;w=N*3。不会有错误