Cropping the Image Bounding Boxes

20 vues (au cours des 30 derniers jours)
Erysham
Erysham le 22 Sep 2016
Commenté : Massimo Zanetti le 26 Sep 2016
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 commentaire
Massimo Zanetti
Massimo Zanetti le 26 Sep 2016
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.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by