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.
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
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),:);