VOC分割数据集数据增强

分割数据集的正常的数据增强方式:对原始数据和ground-truth做相同的增强变换,代码实现如下。

对于原始数据进行增强的代码:my_Augment_data.m

%图像的水平翻转和垂直翻转
clear;clc

% file_path =  './data1/JPEGImages/';% 图像文件夹路径
% new_file_path = './aug1/JPEGImages/';

file_path =  '~/dataset/mydatababy/full-VOC/JPEGImages/';% 图像文件夹路径
new_file_path = '~/dataset/mydatababy/full-VOC-new/JPEGImages/';

img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像

img_num = length(img_path_list);%获取图像总数量

img_num
if img_num > 0 %有满足条件的图像
    for j = 1:img_num %逐一读取图像
        image_name = img_path_list(j).name(1:end-4);% 图像名
        
        image_name
        image =  imread(strcat(file_path,image_name,'.jpg'));
        
        imageBB = image;
        imageB = image;
        
        for k=1:3
            imageBB(:,:,k)=flipud(image(:,:,k));%上下翻转
            imageB(:,:,k)=fliplr(image(:,:,k));%左右翻转
        end
                               
%         subplot(1,3,1);
%         imshow(image);
%         title('yuan')
% 
%         subplot(1,3,2);
%         imshow(imageBB);
%         title('up-down')
% 
%         subplot(1,3,3);
%         imshow(imageB);
%         title('left-right')
%         
        
        file_name1 = strcat(new_file_path,image_name,'.jpg');
        imwrite(image,file_name1);
        
        new_file_name2 = strcat(new_file_path,image_name,'_2.jpg');
        imwrite(imageBB,new_file_name2);
        
        new_file_name3 = strcat(new_file_path,image_name,'_3.jpg');
        imwrite(imageB,new_file_name3);
        
      
        imageI1=rot90(image,1);%逆时针转90度
        imageI2=rot90(image,2);%逆时针转180度
        imageI3=rot90(image,3);%逆时针转270度
        
        new_file_name4 = strcat(new_file_path,image_name,'_4.jpg');
        imwrite(imageI1,new_file_name4);
        
        new_file_name5 = strcat(new_file_path,image_name,'_5.jpg');
        imwrite(imageI2,new_file_name5);
        
        new_file_name6 = strcat(new_file_path,image_name,'_6.jpg');
        imwrite(imageI3,new_file_name6);
        
        
    end
end


% 
% AA=imread('test/label24/2018_010001.png');%文件名是你自己的哦
% 
% 
% figure;
% 
% subplot(1,3,1);
% imshow(AA);
% title('yuan')
% 
% subplot(1,3,2);
% imshow(BB);
% title('up-down')
% 
% subplot(1,3,3);
% imshow(B);
% title('left-right')
% 
% 
% I=imread('test/label24/2018_010001.png');
% I1=rot90(I,1);%逆时针转90度
% I2=rot90(I,2);%逆时针转180度
% I3=rot90(I,3);%逆时针转270度
% figure
% subplot(2,2,1);
% imshow(I);
% title('原图')
% subplot(2,2,2);
% imshow(I1)
% title('逆时针转90度')
% subplot(2,2,3);
% imshow(I2);
% title('逆时针转180度')
% subplot(2,2,4);
% imshow(I3);
% title('逆时针转270度') 

 对于ground-truth进行数据增强的代码:my_Augment_labels.m

%图像的水平翻转和垂直翻转
clear;clc

%file_path =  './data/JPEGImages/';% 图像文件夹路径
%new_file_path = './aug/JPEGImages/';

% file_path =  './data1/SegmentationClass/';% 图像文件夹路径 %##labels
% new_file_path = './aug1/SegmentationClass/';

file_path =  '~/dataset/mydatababy/full-VOC/SegmentationClass/';% 图像文件夹路径 %##labels
new_file_path = '~/dataset/mydatababy/full-VOC-new/SegmentationClass/';

%img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像

img_path_list = dir(strcat(file_path,'*.png'));%获取该文件夹中所有jpg格式的图像  %##labels

img_num = length(img_path_list);%获取图像总数量

img_num
if img_num > 0 %有满足条件的图像
    for j = 1:img_num %逐一读取图像
        image_name = img_path_list(j).name(1:end-4);% 图像名
        
        image_name
        %image =  imread(strcat(file_path,image_name,'.jpg'));
        image =  imread(strcat(file_path,image_name,'.png')); %##labels

        imageBB = image;
        imageB = image;
        
%         for k=1:3
%             imageBB(:,:,k)=flipud(image(:,:,k));%上下翻转
%             imageB(:,:,k)=fliplr(image(:,:,k));%左右翻转
%         end
        
        
        imageBB(:,:,1)=flipud(image(:,:,1));%上下翻转  %##labels
        imageB(:,:,1)=fliplr(image(:,:,1));%左右翻转
        
%         subplot(1,3,1);
%         imshow(image);
%         title('yuan')
% 
%         subplot(1,3,2);
%         imshow(imageBB);
%         title('up-down')
% 
%         subplot(1,3,3);
%         imshow(imageB);
%         title('left-right')
%         
        
%         file_name1 = strcat(new_file_path,image_name,'.jpg');
%         imwrite(image,file_name1);
%         
%         new_file_name2 = strcat(new_file_path,image_name,'_2.jpg');
%         imwrite(imageBB,new_file_name2);
%         
%         new_file_name3 = strcat(new_file_path,image_name,'_3.jpg');
%         imwrite(imageB,new_file_name3);
        


        file_name1 = strcat(new_file_path,image_name,'.png'); %##labels
        imwrite(image,file_name1);
        
        new_file_name2 = strcat(new_file_path,image_name,'_2.png');
        im
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值