Data auguamtion in Matlab

To enlarge the dataset , I test the function of DA method with Xflection and Yflection. The first quesiton how to apply DA method.

Let's see the code.

randomAffine2d :When XReflection is true (1), the transformation tform reflects images horizontally with 50% probability. By default, the transformation does not reflect images in the horizontal direction.

But I want 100% probability, how to realize this goal?

I have Edit the original file, and you can download it from my resouce, it will has 100% xReflection or YRelfection.

download  function

1 Read the image and label 

%1  read file  and label
I=imread(trainingDataTbl.imageFilename{1}); %% GET IMAGE
%B = cell(size(A));
BoxA=trainingDataTbl.vehicle{1} % GET LABEL
%I = A{1};
sz = size(I)
% if numel(sz)==3 && sz(3) == 3
%     I = jitterColorHSV(I,...
%         'Contrast',0.2,...
%         'Hue',0,...
%         'Saturation',0.1,...
%         'Brightness',0.2);
% end

    annotatedI = insertShape(I,'Rectangle',BoxA);
figure, imshow(annotatedI)
title('Original data')

2 Flect  the image and its coresponding label

% 2  Randomly flip and scale image.
tform = randomAffine2d('XReflection',true,'Scale',[1 1]); %X flection
rout = affineOutputView(sz,tform,'BoundsStyle','CenterOutput');
C = imwarp(I,tform,'OutputView',rout);
figure,imshow(C)
imwrite(C,'xflextion.jpg')
title('Flip data')

% 3 flip label
[D,indices] = bboxwarp(BoxA,tform,rout,'OverlapThreshold',0.25);
    annotatedJ = insertShape(C,'Rectangle',D);
figure, imshow(annotatedJ)
title('Flip data')
% 4test for write image and read again
E=imread('xflextion.jpg');
 size(E)

  annotatedJ = insertShape(E,'Rectangle',D);
figure, imshow(annotatedJ)
title('Flip data from read data')

3 write the flected image and read again

% 4test for write image and read again
E=imread('xflextion.jpg');
 size(E)

  annotatedJ = insertShape(E,'Rectangle',D);
figure, imshow(annotatedJ)
title('Flip data from read data')

 XReflection or Y Refection  with 100% prabobility

download  function

call the function with DA method

%test yReflection
%trainingDataTbl=gTruth(1:10,:);
%YReflection
Action='YReflection'
strpath='G:\DA2021\YFlection'
YFlipGrth = DAFlipAll(gTruth,Action,strpath);

%XReflection
Action='XReflection'
strpath='G:\DA2021\XFlection'
XFlipGrth = DAFlipAll(gTruth,Action,strpath);

enlarge the dataset

%% concat with DA dataset
            gTruthDA=vertcat(gTruth,YFlipGrth,XFlipGrth);
            size(gTruthDA)

%% 数据集DA
rng(0);

shuffledIndices = randperm(height(gTruthDA));
idx = floor(0.6 * length(shuffledIndices) );

trainingIdx = 1:idx;
trainingDataTbl = gTruthDA(shuffledIndices(trainingIdx),:);

validationIdx = idx+1 : idx + 1 + floor(0.1 * length(shuffledIndices) );
validationDataTbl = gTruthDA(shuffledIndices(validationIdx),:);

testIdx = validationIdx(end)+1 : length(shuffledIndices);
testDataTbl = gTruthDA(shuffledIndices(testIdx),:);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值