MATLIB 多个子文件夹批量创造测试文件

来源:互联网 发布:hadoop数据目录配置 编辑:程序博客网 时间:2024/04/30 14:03
maindir='Z:\\ ';writepath='Z:\\ ';%fp = fopen(maindir,'wt');subdir =dir( maindir );   % 先确定子文件夹for i = 3 : 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 = 3 :length( images )        imagepath = fullfile( maindir, subdir( i ).name, images( j ).name  );        img = imread( imagepath );         subplot(3,3,1)        imshow(img)        title('original');        b=imrotate(img,3,'nearest');        b = imresize(b, [32 18]);        subplot(3,3,2)        imshow(b)        title('rotate 5');        c=imrotate(img,-3,'nearest');        c = imresize(c, [32 18]);        subplot(3,3,3)        imshow(c)        title('rotate -5');       SE1=strel('ball',2,2);       erode=imerode(c,SE1,'same'); %erode       erode = imresize(erode, [32 18]);       subplot(3,3,4)       imshow(erode);       title('erode');       SE2 = strel('disk', 1);       dilate=imdilate(c,SE2,'same'); %dilate       dilate = imresize(dilate, [32 18]);       subplot(3,3,5)       imshow(dilate)       title('dilate');       V=0.008;       Noisy=imnoise(c,'gaussian',0,V);       subplot(3,3,6)       imshow(Noisy)       title('gaussian noise');       salt=imnoise(c,'salt & pepper',0.02); %加入椒盐躁声       subplot(3,3,7)       imshow(salt)       title('salt & pepper noise');      % fprintf(fp, '%d \n', dex);   nameimg= [images( j ).name(1:end-4),'_0.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(b,imagepath);      nameimg= [images( j ).name(1:end-4),'_1.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(c,imagepath);        nameimg= [images( j ).name(1:end-4),'_2.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(erode,imagepath);        nameimg= [images( j ).name(1:end-4),'_3.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(dilate,imagepath);        nameimg= [images( j ).name(1:end-4),'_4.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(Noisy,imagepath);        nameimg= [images( j ).name(1:end-4),'_5.bmp'];   imagepath = fullfile( writepath, subdir( i ).name,nameimg);   imwrite(salt,imagepath);       endendfclose(fp);

0 0