How can I resize images and bounding boxes on dataset?
5 次查看(过去 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!