cv.jit.erode in jit.gen?

geddonn's icon

Hi guys, I am wondering how to implement cv.jit.erode in jit.gen.
It doesn't sound like it would be too hard but it's got me stumped.

The basic idea behind it is to mark a pixel as on only if all of it's neighbours are also on.

It also has a function to give each pixel the minimum value of the pixels around it.

I know a little on how to work with planes of data in jit.gen but am not sure how to run functions that refer to individual pixels.

Wesley Smith's icon
Max Patch
Copy patch and select New From Clipboard in Max.

You need to use the nearest op in this case. The other alternative is the sample op, but it interpolates, which messes up an erode type operation. nearest takes a coord from [0, 1] to determine which pixel is grabs. To get the coordinate of a pixel offset from the current pixel being processed, you can use the value 1/dim as the delta between pixels:

geddonn's icon

Thanks for the response and the patch.

I seem to get only a few pixels returned from the output of the patch though.

Max Patch
Copy patch and select New From Clipboard in Max.

This is your patch v cv.jit.erode

Wesley Smith's icon
Max Patch
Copy patch and select New From Clipboard in Max.

The description from the help patch about what the operator does isn't the entire story. It's actually more general. Here's a modified patch that does what the object is doing:

geddonn's icon

Ah this is perfect. Thanks for the open CV source also. I need to practice visualising equations in max. I've always had trouble with that.