# Matlab to Opencv equivalent

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
```

code:

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)"

You don't needed this

`loc=find(edges_2)`

. It is equivalent to assembler`goto: edges_2`