【MATLAB图像读取】

该博客介绍了如何使用MATLAB进行图像的批量读取与处理。包括手动选择单个图像或Excel文件,以及指定路径下单个文件夹和多个子文件夹中TIFF图像的批量读取,并对图像进行去噪等处理,最后保存处理后的图像。
摘要由CSDN通过智能技术生成

1、手动选择图像或excel

%% 手动选择图像或excel
file_path_out = uigetdir('*.*','please chioce a folder');
if (isequal(file_path_out,0))
    return;
end
test = fullfile(file_path_out,'backgroundnoise.tif');
Image = imread(test);
%test = fullfile(file_path_out,'samples.xlsx');
%[num1,txt1,raw1] = xlsread(test,'Sheet1');

2、指定路径下,单个文件夹下图像的批量读取与处理

%% 指定路径下,单个文件夹下图像的批量读取与处理
img_file_path =  'D:\images\backgroundnoise\';%图像文件夹路径  
img_list = dir(strcat(img_file_path,'*.tif'));%当前文件夹中所有tif格式的图像  
img_num = length(img_list);%图像总数量 
I=cell(1,img_num);

for j = 1:img_num %逐一读取图像  
    img_name = img_list(j).name;
    img =  imread(strcat(path,img_name));
    I{j} = img;
    fprintf('%d %s\n',j,strcat(img_file_path,img_name));% 显示正在处理的图像名
    img_denoised = denoising(I{j});%function 去噪
    % save
    fname=['D:\denoised\','img',num2str(j),'.tif'];
    imwrite(img_denoised,fname);
end 

3、指定路径下,单个文件夹下图像的批量读取与处理

%% 指定路径下,读取多个子文件夹中的图像
p = genpath('D:\images\backgroundnoise');% 获得文件夹data下所有子文件的路径,这些路径存在字符串p中,以';'分割
length_p = size(p,2);%字符串p的长度
path = {};%建立一个单元数组,数组的每个单元中包含一个目录
temp = [];
for i = 1:length_p %寻找分割符';',一旦找到,则将路径temp写入path数组中
    if p(i) ~= ';'
        temp = [temp p(i)];
    else 
        temp = [temp '\']; %在路径的最后加入 '\'
        path = [path ; temp];
        temp = [];
    end
end  
clear p length_p temp;
%至此获得data文件夹及其所有子文件夹(及子文件夹的子文件夹)的路径,存于数组path中。
%下面是逐一读取文件夹中的图像
file_num = size(path,1);% 子文件夹的个数
for i = 1:file_num
    file_path =  path{i}; % 图像文件夹路径
    img_path_list = dir(strcat(file_path,'*.tif'));
    img_num = length(img_path_list); %该文件夹中图像数量
    if img_num > 0
        for j = 1:img_num
            image_name = img_path_list(j).name;% 图像名
            image =  imread(strcat(file_path,image_name));
            fprintf('%d %d %s\n',i-1,j,strcat(file_path,image_name));% 显示正在处理的路径和图像名
            %function 图像处理
        end
    end
end

注:仅为学习所用,以及日后方便寻找
来源–https://blog.csdn.net/Darlingqiang/article/details/108286336

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值