Paul's solutions looks pretty good to me, but for 5000 ROIs, it might be a little slow, but that might not be too bad. We have something a little like this inside our Draw Dataset plugin - line propagation and then ROI filling, but it's not exposed in a separate function. For reference, I think the line propagation is done in AFNI_3d_linefill() in afni_receive.c and DRAW_2dfiller in plug_drawdset.c. The filling is done in 2D in the slice orientation in which it was drawn. Unless the ROI is blobby, filling in all 3 directions, as noted in Paul's script, may not be what you want, so you may want to tweak that as an option for a particular direction.
In any case,ImageJ and its branch, Fiji, have plugins themselves for doing this kind of job. I'm not sure this will be better than the AFNI way, but you might consider that in the future.
[
forum.image.sc]
[
imagej.net]
Also, just FYI, there are the poly2mask and regionfill functions in Matlab for doing similar processing in 2D.
[
www.mathworks.com]