matlab 遍历图像文件夹
来源:互联网 发布:梦幻西游手游巅峰数据 编辑:程序博客网 时间:2024/04/28 06:43
问题1 :主文件下有多个文件夹如何遍历?
maindir = 'C:\Users\mimashi123\Desktop\Data';
subdir = dir( maindir ); % 先确定子文件夹
for i = 1 : length( subdir )
if( isequal( subdir( i ).name, '.' ) || ...
isequal( subdir( i ).name, '..' ) || ...
~subdir( i ).isdir ) % 如果不是目录跳过
continue;
end
subdirpath = fullfile( maindir, subdir( i ).name, '*.BMP' );
images = dir( subdirpath ); % 在这个子文件夹下找后缀为jpg的文件
% 遍历每张图片
for j = 1 : length( images )
imagepath = fullfile( maindir, subdir( i ).name, images( j ).name );
% imgdata = imread( imagepath ); % 这里进行你的读取操作
end
end
问题2:输出一副图像的RGB三通道值,写入txt文档
img = imread('Testing/input.bmp'); %只能是真彩色的bmp图片
[m n c]=size(img);
imshow(img);
if(c==3) %RGB pic
fid = fopen('rgb.txt','w');
for i=1:m
for j=1:n
fprintf(fid,'%d,%d,%d\t',img(i,j,1),img(i,j,2),img(i,j,3));
end
fprintf(fid,'\n');
end
fclose(fid);
end
问题3: 现在有一个文件夹,文件夹底下有图片,想把每一张图像的RGB分别写入不同的txt文件中
file_path = 'Testing';
img_path_list = dir(fullfile(file_path,'*.bmp'));
img_num = length(img_path_list);
for i = 1: img_num
img = imread(fullfile(file_path,img_path_list(i).name));
[m, n, c ] = size(img);
if(c==3) %RGB pic
id = strcat('rgb',num2str(i),'.txt');
fid = fopen(id,'w'); %这两行是写入不同的txt文件中
for i=1:m
for j=1:n
fprintf(fid,'%d,%d,%d\t',img(i,j,1),img(i,j,2),img(i,j,3));
end
fprintf(fid,'\n');
end
fclose(fid);
end
end
问题4 ,现在有一个文件夹,这个文件夹下有两个文件夹都有图片,遍历两个文件夹的图片,把每一张图像的RGB写入不同的txt文件中:
maindir = 'C:\Users\mimashi123\Desktop\Data';
subdir = dir( maindir ); % 先确定子文件夹
for i = 1 : length( subdir )
if( isequal( subdir( i ).name, '.' ) || ...
isequal( subdir( i ).name, '..' ) || ...
~subdir( i ).isdir ) % 如果不是目录跳过
continue;
end
subdirpath = fullfile( maindir, subdir( i ).name, '*.BMP' );
images = dir( subdirpath ); % 在这个子文件夹下找后缀为jpg的文件
% 遍历每张图片
for j = 1 : length( images )
imagepath = fullfile( maindir, subdir( i ).name, images( j ).name );
img = imread( imagepath ); % 这里进行你的读取操作
[m, n, c ] = size(img);
if(c==3) %RGB pic
id = strcat('rgb',num2str(i),num2str(j),'.txt');
fid = fopen(id,'w');
for x=1:m
for y=1:n
fprintf(fid,'%d,%d,%d\t',img(x,y,1),img(x,y,2),img(x,y,3));
end
fprintf(fid,'\n');
end
fclose(fid);
end
end
end
- matlab 遍历图像文件夹
- Matlab代码-遍历文件夹下所有指定格式的图像
- matlab遍历文件夹
- matlab遍历文件夹 .
- Matlab遍历文件夹,Reshape
- matlab遍历文件夹
- matlab 遍历文件夹内文件
- MATLAB遍历子文件夹及其下文件
- matlab遍历文件夹下的所有文件
- Matlab 文件夹遍历并更改图片尺寸
- matlab遍历指定路径下的文件夹
- 子文件夹的遍历(python、matlab)
- matlab批量保存图像至指定文件夹
- 利用matlab读入文件夹中所有图像
- Matlab读取文件夹下的图像文件名
- MATLAB读取文件夹中的批量图像
- MATLAB 读取一个文件夹中的所有图像
- MATLAB中读取文件夹下所有图像
- 2.停止线程
- 深度卷积神经网络用于图像缩放Image Scaling using Deep Convolutional Neural Networks
- 完全用Python工作---Harness the power of Python
- 算法训练 友好数
- Struts2中访问Servlet API的几种方式
- matlab 遍历图像文件夹
- Android之去掉ListView的点击背景
- 短信验证码
- eclipse插件之plugin.xml
- 火狐中正常显示页面的CSS样式,在IE下完全不识别,页面全乱了
- 算法训练 9-7链表数据求和操作
- hdu 3555 Bomb【数位dp~吖!!!!!】
- Android 自定义ViewGroup
- 卷积神经网络Convolutional Neural Networks