2013-04-01 72 views
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.[email protected]> 
% 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)); 

回答

1

的一個可能的原因是你定義一個函數,它的名字是「大小」。如果是這樣,請將您定義的函數重命名爲另一個名稱。

如果沒有,在你的工作文件夾只有兩個文件,如果輸入的是一個豐富多彩的圖像的情況下,那麼你會遇到在線edge_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。不會有錯誤。

相關問題