Matlab 实现对年龄库的分类

来源:互联网 发布:ubuntu gnome 安装 编辑:程序博客网 时间:2024/06/05 19:59

从网上下载下来一个年龄的数据库wiki可是由于项目的需要,需要将不同年龄段的图片归类到一个区间内。

0-15;16-25;26-40;41-55;56-70;

话不多说,直接上Matlab代码;

clear all;clc;addpath(fullfile('H:\matlab\Jpeg_toolbox'));tic; %% 保存当前时间% matlabpool local 2 %% matlab中并行的方法 2核并行运算file_path='H:\22\wiki\75\';img_path_list = dir(strcat(file_path,'*.jpg'));%%获取该文件夹下的所有JPG图片 strcat连接函数n=length(img_path_list);%%获取图像总数量for i=1:n    image_name = img_path_list(i).name;    COVER=strcat(file_path,image_name);    C_STRUCT = jpeg_read(COVER);    map=regexp(image_name,'_');%% Matlab中使用regexp函数对字符串的提取    temp1=image_name(map(1)+1:map(1)+4);    temp2=image_name(map(2)+1:map(2)+4);    temp1=str2double(temp1); %% 字符串转换为数字    temp2=str2double(temp2);    temp=temp2-temp1;    if temp<=15        jpeg_write(C_STRUCT,['H:\22\output\0-15\',image_name]);    elseif temp>=16 && temp<=25        jpeg_write(C_STRUCT,['H:\22\output\16-25\',image_name]);    elseif temp>=26 && temp<=40        jpeg_write(C_STRUCT,['H:\22\output\26-40\',image_name]);    elseif temp>=41 && temp<=55        jpeg_write(C_STRUCT,['H:\22\output\41-55\',image_name]);    else        jpeg_write(C_STRUCT,['H:\22\output\56-70\',image_name]);    end    fprintf(['第',num2str(i),' 已经-------- ok','\n']);end% matlabpool closetoc; %%程序完成时间% -------------------------------------------------------------------------


以上就可以实现对年龄分类到不同文件夹下面

0 0