I did not run the code, because I don't own the toolbox, but the following lines are very "suspicious":
positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,1));
positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));
I would expect:
positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,1));
positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));
Some suggestions to shorten your code, they are not related to the problem:
You can shorten line 4 to 9 to a single line, avoiding the loop: [positive_samples(1:L).im]=list(4:end).name
And this loop can be replaced as well:
tempmat=[];
count=1;
for l=1:le
for m=1:wi
if h1(l,m)==1
tempmat(count,1)=l;
tempmat(count,2)=m;
count=count+1;
end
end
end
shorter and faster code:
[y,x]=find(h1);
tempmat=[y x];