Skip to content

Commit ff4a471

Browse files
author
pdollar
committed
BUG FIX in bb = MaskApi.toBbox(R) !!!
Details: this bug only affected extraction of bounding boxes for RLEs that took full image height. In this case the returned bb should have y=0 and box_height=image_height. However, the bug would have the y values incorrect for such boxes (the extraction of the bbox would miss the fact that the RLE encoded mask loops from y=h-1 to y=0 in certain cases). An example (in Matlab) of the bug before the fix is as follows: M=uint8([0 1; 1 1]); bbox=MaskApi.toBbox(MaskApi.encode(M)) This would return [0 1 2 1] instead of [0 0 2 2]. This has now been corrected.
1 parent 440d145 commit ff4a471

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

common/maskApi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ void bbNms( BB dt, siz n, uint *keep, double thr ) {
132132

133133
void rleToBbox( const RLE *R, BB bb, siz n ) {
134134
siz i; for( i=0; i<n; i++ ) {
135-
uint h, w, x, y, xs, ys, xe, ye, cc, t; siz j, m;
135+
uint h, w, x, y, xs, ys, xe, ye, xp, cc, t; siz j, m;
136136
h=(uint)R[i].h; w=(uint)R[i].w; m=R[i].m;
137137
m=((siz)(m/2))*2; xs=w; ys=h; xe=ye=0; cc=0;
138138
if(m==0) { bb[4*i+0]=bb[4*i+1]=bb[4*i+2]=bb[4*i+3]=0; continue; }
139139
for( j=0; j<m; j++ ) {
140140
cc+=R[i].cnts[j]; t=cc-j%2; y=t%h; x=(t-y)/h;
141+
if(j%2==0) xp=x; else if(xp<x) { ys=0; ye=h-1; }
141142
xs=umin(xs,x); xe=umax(xe,x); ys=umin(ys,y); ye=umax(ye,y);
142143
}
143144
bb[4*i+0]=xs; bb[4*i+2]=xe-xs+1;

0 commit comments

Comments
 (0)