OpenCV update, Heaviside Step Function, deriving parametric functions of shapes, Sobel filter

just looking online and it does seem to indicate that my approach is correct at least the result seem to match the online quality

the traditional lena picture is expected to give this output


can you post the output of openCv please so we can compare?

The best approximation I got compared to yours is this.
( Of course click to amplify)
The last exact same picture you posted is from the tutorial I linked.
You have to invert it.

BTW .“I meant setting the multiplier to 1 not zero”
Of course, I played with all the parameters.

1 Like

the first one is very close, perhaps a bit more noise, and the second one is just extracting the vertical lines.

In any case I’m quite pleased with the result.

Hehe. The first one is yours !! You asked for a comparison.
I just changed the offset a little. :grin: :grin:

1 Like

Then it seems openCv should be able to produce the same result, however the bottom image is missing the horizontal edges.

With sobel filter I doubt it. The lines are vertical because I’ve choose the derivative parameters that way to give some contrast at least. See here just some lines and pictures. You can change the derivative parameter from 0 to 2. I’ve tried also the ScharrEdges and the CannyEdges but none of them gives an outcome as nice as yours. I’m afraid you have to accept the credit.

2 Likes

one last thing I forgot

sobel.pixels[p] = color(255-k+offset);
sobel.pixels[p] = color(255-(k-b2));
sobel.pixels[p] = color(b2-k);

these correspond to the 3 outputs of the car image not sure they are in order, but one gives clean lines, the next clean lines with some shading and the last combines the derived lines with the brightness of the original image for a pencil colored look.

Feel free to use the repo, hopefully I’ll make it into a library later.

2 Likes

That’s the way to go for a library. Looking forward.

1 Like

I still didn’t give up.
Bryan Chung has made a CVImage class that makes it possible to use the latest OpenCV library.So now you can use full range of parameters in the sobel function. With this I could give the house picture some more details now, but still not as your outcome.


If I remember well you wrote somewhere that you are writing a neural network to do character recognition. The newer openCV makes YOLO (You only look once) detection possible in Processing.
See here a video of Real-Time Object Detection with openCV

2 Likes

For those whom interested:
To use the latest openCV library (4.4.0 at the time of this post) you need to paste the jar’s and dll in a folder “code” within your sketch folder.
I’ve prepared a zip of this folder with all the jar’s build and dll. You can download it here.
I also made a new repository here, where I plan to post various codes that can’t be done with the older openCV-processing version. An example is for example the warpAffine function.

This I also solved and posted it on my repo here. It uses the same image and thus the same result as on the openCV tutorial about hierarchy. This is handy when you convert contours into shapes and you want holes in them.

5 Likes

Just adding thresholding at the moment this produces an image which is binary based on the output of the sobel, with the aim of using histeresis to thin the lines too and produce canny edge detection, still have to read some more into the process, but the thresholding currently works this combined with my previous work should provide good contours which you can trim dependent on size. I can also speed it up by only scanning for walls which will allow processing of images greater than the current resolution.

Will post results later.

1 Like

The program has now been updated with shaders, so everything now works using gpu at 60fps.

Only issue I’m trying to overcome is the speed is fine so long as the canvas is manipulated without posting to a PImage or creating an image using get afterwards. If I do then the speed is reduced by a factor of 2. is there an alternative method to convert canvas data to PImage.

2 Likes

repo updated

chain together image operations and create a workflow like this.

String []wf = {"gaussianS(2.0,5)","sobel(10.0)","sobelMax2(200.0)","canny(5,130.0,50)"};

call the workflow like this.

img.displayWF(wf);

click through workflow to see output of operations.

void displayWF(String []s){
    logic();
    workflow(s);
    if(imagesWF.size()>0)
    image(imagesWF.get(counter),x,y);
    
  };

I’m currently pretty happy with the cpu version of canny.
blur
Screen Shot 10-28-20 at 03.12 PM
sobel
Screen Shot 10-28-20 at 03.12 PM 001
surpress max
Screen Shot 10-28-20 at 03.12 PM 002
finish
Screen Shot 10-28-20 at 03.12 PM 003

there’s always a few bits here and there, I guess the next steps would be dilation and erosion.
This version currently doesn’t have the contour tracing, however that step is complete it just has to be added to the code, and then edges can be extracted from the picture.

Working on a shader version to speed things up a bit but currently running into some problems extracting the sobel gradient required for the max surpression, will update when fixed.

3 Likes

You are doing a really nice job with these filters.
I just tested them all out;
I hope to see a library.

3 Likes

Thank you for your help!