How to use ImageMiscOps.filter and BoofLambdas?

7 views
Skip to first unread message

Jose Luis Albarral

unread,
Oct 20, 2023, 10:03:17 AM10/20/23
to BoofCV
Hi all,

Trying boofCV for some robotic vision stuff ...

I need to apply a mask (GrayU8) to an image (Planar<GrayU8>) just the same as done in openCV ... So, just keeping the image's pixels that correspond to the 1's pixels in the mask and the rest being zeroed.

What's the proper (direct & fast) way to do this in boofCV?

I got into these 2 methods: 

ImageMiscOps.filter()
ImageMiscOps.findAndProcess()


But couln't find a related howto in the docs nor they appear in any of the boofcv.examples as of 1.0.0 version.

A hint on this or a direction where to look for would be much appreciated.

Thanks and happy coding!
JL



Jose Luis Albarral

unread,
Oct 20, 2023, 12:37:28 PM10/20/23
to boo...@googlegroups.com
As sometimes happens ... when you launch the question the answer magically comes to you ... 😂

Usages found in code itself:

GrayU8 expected = grayU8.createSameShape().setTo(grayU8);
...
ImageMiscOps.filter(expected, ( x, y, d ) -> scores.get(x, y) >= threshold ? maxRange : d);


GrayF32 inverseDepth = new GrayF32(width, height);
var scores = new GrayF32(grayU8.width, grayU8.height);
...
ImageMiscOps.findAndProcess(inverseDepth, ( v ) -> v > 0, ( int x, int y ) -> {inverseDepth.data[inverseDepth.getIndex(x, y)] += tolerance - 0.0001f; return false; });

Thanks anyway! 
JL

--
You received this message because you are subscribed to a topic in the Google Groups "BoofCV" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/boofcv/j3H-8JhGZVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to boofcv+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/boofcv/07dad52a-0fec-4c5e-8aae-28fae734b630n%40googlegroups.com.

Jose Luis Albarral

unread,
Oct 20, 2023, 12:53:14 PM10/20/23
to boo...@googlegroups.com
Solved by filtering each of the 3 bands separately !!

            ...
            Planar<GrayU8> image2 = image.clone();
            GrayU8 submask = mask.getImage();
            GrayU8 red = image2.getBand(0);
            GrayU8 green = image2.getBand(1);
            GrayU8 blue = image2.getBand(2);
            ImageMiscOps.filter(red, (x, y, d) -> submask.get(x, y) > 0 ? red.get(x, y) : 0);
            ImageMiscOps.filter(green, (x, y, d) -> submask.get(x, y) > 0 ? green.get(x, y) : 0);
            ImageMiscOps.filter(blue, (x, y, d) -> submask.get(x, y) > 0 ? blue.get(x, y) : 0);
            return image2;

And the question for boofcv experts ... isn't there a faster way that avoids having to walk the same mask 3 times?

Thanks again,
JL

Reply all
Reply to author
Forward
0 new messages