Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Quickly draw MSER region (in Java)

I have several MSER regions detected and for each one I'd like to convert them into a binary mask. All the existing solutions say to just loop over every point in each MSER and set that pixel to 255. This indeed works....but it is very slow! Is there any better/faster solution?

In Python it is very easy and very fast...

regions, boxes = mser.detectRegions(img)
mask=np.zeros(img.shape)
for n,p in enumerate(regions):
    mask[p[:,1],p[:,0]]=n+1

But I'm needing a solution in Java.

Quickly draw MSER region (in Java)

I have several MSER regions detected and for each one I'd like to convert them into a binary mask. All the existing solutions say to just loop over every point in each MSER and set that pixel to 255. This indeed works....but it is very slow! Is there any better/faster solution?

In Python it is very easy and very fast...

regions, boxes = mser.detectRegions(img)
mask=np.zeros(img.shape)
for n,p in enumerate(regions):
    mask[p[:,1],p[:,0]]=n+1

But I'm needing a solution in Java.

mser.detectRegions(img,regions,boxesmat);
mask.setTo(new Scalar(0));
for ( int n = 0; n < regions.size(); n++){
    for ( int p = 0; p < regions.get(n).rows(); p++){
        int r = (int)regions.get(n).get(p,0)[1];
        int c = (int)regions.get(n).get(p,0)[0];
        mask.put(r,c,n+1);
    }
}