How can I resize images and bounding boxes on dataset?
6 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Computer Vision Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!