How can I resize images and bounding boxes on dataset?

6 views (last 30 days)
I'm trying to resize the images and bounding boxes of a combined datastore with a function to fit their size with resnet18 input size to create a YOLO object detector, but it displays an error when I execute it. This is the function (I'm sorry the names are in spanish):
function data = ReescalarDataset(data)
tamanio = [224 224 3]; %tamaño de entrada requerido por resnet18
% data{1} es la imagen
escala = tamanio./size(data{1},[1 2]);
data{1} = imresize(data{1},tamanio);
% data{2} contiene la bounding box
data{2} = bboxresize(data{2},escala);
end
And when I execute this
dataEscalado = transform(data, @ReescalarDataset)
pruebaGroundTruth = preview(dataEscalado)
It displays this error
Invalid transform function defined on datastore.
The cause of the error was:
Arrays have incompatible sizes for this operation.
Error in ReescalarDataset (line 7)
escala = tamanio./size(data{1},[1 2]);
Error in matlab.io.datastore.TransformedDatastore/applyTransforms (line 610)
data = ds.Transforms{ii}(data);
Error in matlab.io.datastore.TransformedDatastore/read (line 222)
[data, info] = ds.applyTransforms(data, info);
Error in matlab.io.datastore.TransformedDatastore/preview (line 295)
dataFromRead = read(copyds);
I don't know other way to do the scaling of both the image and the bounding box.

Accepted Answer

Birju Patel
Birju Patel on 27 Apr 2022
The error is caused by dividing a three element vector with a two element vector. Make the follow change to your code:
escala = tamanio(1:2)./size(data{1},[1 2]);

More Answers (0)

Categories

Find more on Computer Vision Toolbox in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!