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
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