Error while run the code

1 次查看(过去 30 天)
function veins = miura_max_curvature(img, fvr, sigma)
winsize = ceil(4*sigma);
[X,Y] = meshgrid(-winsize:winsize, -winsize:winsize);
the above function is called in the main script
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));
the above function is called in the main function
img = im2double(imread('veinvein.jpg')); % Read the image
img = imresize(img,0.5); % Downscale image
fvr = lee_region(img,4,20); % Get finger region
%% Extract veins using maximum curvature method
sigma = 3; % Parameter
v_max_curvature = miura_max_curvature(img,fvr,sigma);
% Binarise the vein image
md = median(v_max_curvature(v_max_curvature>0));
v_max_curvature_bin = v_max_curvature > md;
%% Visualise
% Overlay the extracted veins on the original image
overlay_max_curvature = zeros([size(img) 3]);
overlay_max_curvature(:,:,1) = img;
overlay_max_curvature(:,:,2) = img + 0.4*v_max_curvature_bin;
overlay_max_curvature(:,:,3) = img;
above code is the main script
Error in miura_max_curvature (line 27)
winsize = ceil(4*sigma);
how to solve the following error
Unable to perform assignment because the size of the left side is 44-by-483 and the size of the right side is 44-by-161-by-3.

采纳的回答

Image Analyst
Image Analyst 2020-7-17
Bran Ton wrote some non-robust code when he did this:
[img_h, img_w] = size(img);
Never do that with an image. If img happens to be a color image, img_w will give you the number of columns times the number of color channels (3) instead of the number of columns like you were expecting. He should have done this:
[img_h, img_w, numberOfColorChannels] = size(img);
When you do it like I said, what does numberOfColorChannels end up being? 1 or 3?

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by