How can I resize images and bounding boxes on dataset?

11 vues (au cours des 30 derniers jours)
Jesús Silva
Jesús Silva le 25 Avr 2022
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);
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 (line 610)
data = ds.Transforms{ii}(data);
Error in (line 222)
[data, info] = ds.applyTransforms(data, info);
Error in (line 295)
dataFromRead = read(copyds);
I don't know other way to do the scaling of both the image and the bounding box.

Réponse acceptée

Birju Patel
Birju Patel le 27 Avr 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]);

Plus de réponses (0)


En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by