Hello Mat

 找回密码
 立即注册
查看: 5967|回复: 0

获取文件夹内的全部图像文件(根据图像后缀格式)

[复制链接]

1294

主题

1520

帖子

112

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22635
发表于 2017-8-25 23:00:37 | 显示全部楼层 |阅读模式
获取文件夹内的全部图像文件:
  1. % 获取训练样本
  2. clc,clear,close all
  3. warning off
  4. format longG
  5. % 提取图像的特征
  6. addpath(genpath('../code'))
  7. addpath(genpath('../ABC'))
  8. %% ABC 参数初始化
  9. maxiter = 10;  % 迭代次数
  10. sizepop = 10;  % 种群数量
  11. %% 遍历图像
  12. Features1 = [];
  13. file_path =  './孔洞/';% 图像文件夹路径
  14. img_path_list = dir(strcat(file_path,'*.bmp')); % 获取该文件夹中所有bmp格式的图像
  15. img_num = length(img_path_list);  % 获取图像总数量
  16. if img_num > 0                    % 有满足条件的图像
  17.     for j = 1 :img_num            % 逐一读取图像
  18.         image_name = img_path_list(j).name;   % 图像名
  19.         fprintf('正在处理的图像: %d %s\n',j,strcat(file_path,image_name));  % 显示正在处理的图像名
  20.         img =  imread(strcat(file_path,image_name));
  21.         if size(img,3)>1
  22.             img = rgb2gray(img);
  23.         end
  24.         [bw, zbest, fitnesszbest] = ABC_seg(img,maxiter,sizepop);
  25. %         figure(1),imshow(bw,[])
  26.         Feature = Extract_Image_Feature(img, bw);
  27.         Features1 = [Features1; Feature];
  28.         %图像处理过程 省略
  29.     end
  30. end

  31. %% 保存结果数据
  32. save TrainData.mat

  33. rmpath(genpath('../code'))
  34. rmpath(genpath('../ABC'))
复制代码




算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-5-5 21:39 , Processed in 0.216081 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表