Well the first loop for( i = 0; i < d+2; i++ ) {...} is used, to fill the Histogramm of the descriptor where d is the width of the descriptor + 2 (e.g. with the 128 elements vector 4 + 2). It is initially filled with zeroes, so it would not occur the possibility, that a histogram bin would point to null instead of a value.
The second loop for( i = -radius, k = 0; i <= radius; i++ ) {...} is used pick the pixel values around the certain keypoint and to calculate the orientation and magnitude of it. The radius value determines what size this window where pixels will be looked up have. e.g. if radius is 15 the algorithms lookup window of the KeyPoint 100,100 would be a rectangle with the upperLeft and bottomRight coordinates 85, 85 and 115, 115
Well the first loop for( i = 0; i < d+2; i++ ) {...} is used, to fill the Histogramm of the descriptor where d is the width of the descriptor + 2 (e.g. with the 128 elements vector 4 + 2). It is initially filled with zeroes, so it would not occur the possibility, that a histogram bin would point to null instead of a value.
The second loop for( i = -radius, k = 0; i <= radius; i++ ) {...} is used pick the pixel values around the certain keypoint and to calculate the orientation and magnitude of it. The radius value determines what size this window where pixels will be looked up have. e.g. if radius is 15 the algorithms lookup window of the KeyPoint 100,100 would be a rectangle with the upperLeft and bottomRight coordinates 85, 85 and 115, 115