0

我尝试进行手指静脉特征提取我有两个文件我收到了这个错误(第 29 行),它在第二个文件中

[img_h, img_w] = size(img);

没有足够的输入参数。第一的

% 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

mask_height=4; % Height of the mask
mask_width=20; % Width of the mask
[fvr, edges] = lee_region(img,mask_height,mask_width);

% Create a nice image for showing the edges
edge_img = zeros(size(img));
edge_img(edges(1,:) + size(img,1)*[0:size(img,2)-1]) = 1;
edge_img(edges(2,:) + size(img,1)*[0:size(img,2)-1]) = 1;

rgb = zeros([size(img) 3]);
rgb(:,:,1) = (img - img.*edge_img) + edge_img;
rgb(:,:,2) = (img - img.*edge_img);
rgb(:,:,3) = (img - img.*edge_img);

% Show the original, detected region and edges in one figure
figure;
subplot(3,1,1)
  imshow(img,[])
  title('Original image')
subplot(3,1,2)
  imshow(fvr)
  title('Finger region')
 subplot(3,1,3)
  imshow(rgb)
  title('Finger edges') 

这是第二个文件

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));
4

1 回答 1

1

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

如果没有,如果您的工作文件夹只有两个文件,如果输入是彩色图像,那么您将在线上的主文件中遇到错误edge_img(edges(1,:) + size(img,1)*[0:size(img,2)-1]) = 1;,而不是在第二个文件中。我刚刚测试了它。要解决此错误,您需要将所有输入图像(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。不会有错误。

于 2013-04-01T07:41:18.037 回答