MATLAB Answers

utilising imwarp and affine2d for transformation on dataset

4 views (last 30 days)
Matpar on 9 Feb 2020
Answered: Divya Gaddipati on 13 Feb 2020
Hi Professionals,
I am trying to perform tranformations on a small dataset of 40 images, is there a method to pass all of the images into the function so that it transform all the images
I am interested in the affine2d random method and the imwarp!!
I lack the knowledge of how to code this!
ERROR: everytime I try my to pass in my data set the system prompts with an error!!
Error using imwarp>parseInputs (line 342)
The value of 'InputImage' is invalid. Expected input number 1, A, to be one of these types:
logical, uint8, uint16, uint32, int8, int16, int32, single, double
Instead its type was table.
Error in imwarp (line 190)
parsedInputs = parseInputs(varargin{:});
Error in test15 (line 85)
augimdsTrainwarp = imwarp(SgTruth,tform1)
Can a professional assist me with gaining the knowledge on how to go about coding this example?
I have tried the singe image and it worked! what i am trying to do is get the function to accpet all 40 images and present them in their new transformed state!!
SgTruth is my data set of 40 images!!!
pixelRange = [-30 30];
[imdsTrain,imdsValidation] = digitTrain4DArrayData;
imageAugmenter = imageDataAugmenter('RandRotation',[-180 180],...
'RandXTranslation',pixelRange, ...
%% imageSize = [227 227 3];
augimdsTrain = augmentedImageSource(inputSize(1:2),imdsTrain,imdsValidation,...
augimdsTrain.MiniBatchSize = 16
% tform1 = affine2d([2 0.33 0; 0 1 0; 0 0 1])
% augimdsTrainwarp = imwarp(SgTruth,tform1)

Answers (1)

Divya Gaddipati
Divya Gaddipati on 13 Feb 2020
You can concatenate all the images in a matrix of size m x n x c x t where
m = width, n = height, c = number of channels, t = total number of images.
Use randomAffine2d to define the transformation and then use imwarp on the concatenated matrix
For example:
tform = randomAffine2d('Scale',[0.95,1.05],'Rotation',[-30 30]);
res = imwarp(im_3d, tform);
For more information on randomAffine2d, you can refer to the following link:
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by