How can I resize images and bounding boxes on dataset?

11 ビュー (過去 30 日間)
Jesús Silva
Jesús Silva 2022 年 4 月 25 日
回答済み: Birju Patel 2022 年 4 月 27 日
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.


Birju Patel
Birju Patel 2022 年 4 月 27 日
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]);

その他の回答 (0 件)


Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by