Matlab to Opencv equivalent

asked 2020-02-21 03:58:10 -0600

JT3D gravatar image

updated 2020-02-21 04:04:17 -0600

supra56 gravatar image

Hi guys, Would anybody be able to translate the following Matlab code into equivalent Opencv pseudo code. What it should be doing is cleaning up some edges in an image (image is already just edges but needs to be cleaned up). I've added my comments after // on each line as to what I think it's doing but any help advise would be greatly appreciate. I'm porting to c++ and have never used the Matlab code generator so not sure if that could help?

Matlab function:

function image=threshold(edges, lower, upper)
edges_1=edges > lower;  // threshold the input edges image on the lower value - opencv equivalent return Mat > lower

edges_2=edges > upper; // threshold the input edges image on the higher value - opencv equivalent return Mat > upper

seg_1=bwlabel(edges_1); // connected components???? - Opencv equivalent - connected components but not sure????

seg_2=bwlabel(edges_2); // connected components??? - Opencv equivalent - connected components but not sure????

loc=find(edges_2); // ??? No idea on the equivalent

seg=seg_1(loc); // ?? No idea on equivalent

seg=unique(seg); ?? I think this is getting just inique segments from above but not clear- no idea on opencv equivalent

image=ismember(seg_1, seg); // A check to see is the unique segs are part of se1g?? - no idea on opencv equivalent
edit retag flag offensive close merge delete

Comments

code:

Def _image(edges, lower, upper):
        _edges =   cv2.threshold(edges,  lower, upper,  cv2.THRESH_BINARY)
       return _edge
supra56 gravatar imagesupra56 ( 2020-02-21 04:16:31 -0600 )edit

I think it's doing something cleverer in this code than plain thresholding that is related to connected components. I'm just not exactly what it is doing to filter out unwanted edges - especially from this line onwards "loc=find(edges_2)"

JT3D gravatar imageJT3D ( 2020-02-21 04:58:35 -0600 )edit

You don't needed this loc=find(edges_2). It is equivalent to assembler goto: edges_2

supra56 gravatar imagesupra56 ( 2020-02-21 09:07:37 -0600 )edit