Cropping the Image Bounding Boxes

18 次查看(过去 30 天)
Erysham
Erysham 2016-9-22
Hello everyone. I wanted to crop the region of interest(ROI) from set of images, let say image a,b and c based on the provided bounding box information. For your information, different image has different bounding box sizes.
The first step I did was, I import the txt file containing bounding box information and save it as table matrix, named as bbtrycrop1.mat. Please see the attachment referring this file.
Then, I read those images from a folder, followed by cropping the bounding box x1,y1,x2,y2 using imcrop function.
However, it was unsuccessful after several times attempts fixing the following codes.
I need any kind of assistance regarding this..Many thanks in advance.
Here is the codes:
if true
% code
srcFiles = dir('D:\Phd Study\Lab work-object detection\extractboundingbox\trycrop\*.jpg');
load bbcrop1.mat
for i = 1 : length(srcFiles)
filename = strcat('D:\Phd Study\Lab work-object detection\extractboundingbox\trycrop\',srcFiles(i).name);
I = imread(filename);
j=size(bbtrycrop1,1);
for b = 1 : length(j)
line1=bbtrycrop1(1,:);
x1=line1(:,2);
y1=line1(:,3);
x2=line1(:,4);
y2=line1(:,5);
I2{b} = imcrop(I,[x1 y1 x2 y2]);
end
end
  1 个评论
Massimo Zanetti
Massimo Zanetti 2016-9-26
The vector defining the crop size and position is NOT of the type
[x1 y1 x2 y2]
but instead
[xmin ymin width height]
You have to provide top-left corner point and size of the crop window.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by