using my function for folder of images

3 次查看(过去 30 天)
Rd
Rd 2020-11-12
This is the code for finger region localization.
i need to use this code for the images in the folder.
my images are in the folder: C:\Users\manjurama\Desktop\training and testing\Training
under Training i have 10 subfolders. Each have 15 images.
how can i use the folowing code for my images. finally i need to store the output in the 10 subfolder.
Kindly help me to do this. Thanks in advance.
% This script shows how the finger region and edges can be detected.
img = im2double(imread('finger.bmp')); % 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);
function [region, edges] = lee_region(img, mask_h, mask_w)
[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));

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by