Cropping the Image Bounding Boxes

조회 수: 17 (최근 30일)
Erysham
Erysham 2016년 9월 22일
댓글: Massimo Zanetti 2016년 9월 26일
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