OpenCV GPU Primitives - opencv

Are the OpenCV primitives based on the CUDA Nvidia Performance Primitives (NPP)?.
By primitives I mean the same ones implemented in the NPP library, for example: boxFilter, Mirror, Convolution...
I would like to know about this issue as I'm planning use the NPP library. However, OpenCV has more functions that could help me for example in border treatment for image processing.

OpenCV uses NPP library for some functions. But it is hard to create a compelete list of such functions.
Some functions uses only NPP implemetation (boxFilter, graphcut, histEven).
Other functions uses different implemetations for different input parameters. For example, cv::gpu::resize uses NPP for some input parameters (CV_8UC1 and CV_8UC3 types, INTER_NEAREST and INTER_LINEAR interpolation mode) and for other parameters it uses own implementation.

Great webinar about OpenCV on a GPU using CUDA
Video - http://on-demand.gputechconf.com/gtc/2013/webinar/opencv.mp4
Slides PDF - http://on-demand.gputechconf.com/gtc/2013/webinar/opencv-gtc-express-shalini-gupta.pdf

Related

fft numpy style on iOS accelerate with non power of two data length

I'm working on reimplementing python code on iOS (swift).
I need to do an fft (numpy style) on chunks of 1D data. each with size 1050 (windowed audio data).
Thankfully I found related explanation and snippet of code on how to do iOS fft in numpy style (link).
However, I'm stuck where accelerate framework supports doing fft only on a power of 2 input data length (or more recently, f * 2^n, where f is 3, 5, or 15 and n is at least 3).
I tested my python code on window size 1050. Working great for my use case. But it is not straightforward to implement on iOS, because of the above limitation.
It is not so easy to dig into numpy c code to know how they're doing it for non power of two lengths. This answer was a good starting point for me, but still didn't get it.
Speed here is also important, that's why I'm not considering a brute force dft.
Any guidance here would be really appreciated.
IIRC, for fft, under-the-hood, numpy uses fftpack, a C conversion of an old NCAR Fortran math library. The actual numpy fft is not implemented in Python code. You could very likely compile some fftpack C code using Xcode, and use a bridging header to call it from iOS Swift code.
Your answers/comments guided me to use c/c++ code to get the desired result. (I didn't think of that as an option initially).
I ended up using opencv dft function (which internally implements fft) that produces similar results to numpy's fft (+ it is faster than numpy, according to their docs).

How to create a convex hull of all binary spots in ImageJ

I have a binary image of separated spots.
Is there any ImageJ plugin that could construct convex hull of all spots?
Or could you recommend another program, not ImageJ, that can do this?
With OpenCV you can use findContours() and then convexHull()
You can see a complete example here: https://docs.opencv.org/2.4/doc/tutorials/imgproc/shapedescriptors/hull/hull.html
OpenCV is a library, which means that you have to code the program yourself. It has bindings for Java, python and many other languages. You can easily find the same example in other languages:
Convex Hull on Java Android Opencv 2.3
Provided you have an 8-bit (binary) image in ImageJ, you can run the following Groovy script from the script editor to get the convex hull as current selection:
## ImagePlus imp
import ij.gui.PolygonRoi
import ij.gui.Roi
import ij.plugin.filter.ThresholdToSelection
import ij.process.ImageProcessor
imp.getProcessor().setThreshold(128,255,ImageProcessor.NO_LUT_UPDATE)
roi = ThresholdToSelection.run(imp)
proi = new PolygonRoi(roi.getContainedFloatPoints(), Roi.POLYGON)
chRoi = new PolygonRoi(proi.getConvexHull(), Roi.POLYGON)
imp.setRoi(chRoi)
Note that in general, this type of question might be considered off-topic here and is better asked on the ImageJ forum, where you'll get advice from image processing experts.
Edit-Selection-make selection, then ConvexHull

Metal Compute Kernel vs Fragment Shader

Metal supports kernel in addition to the standard vertex and fragment functions. I found a metal kernel example that converts an image to grayscale.
What exactly is the difference between doing this in a kernel vs fragment? What can a compute kernel do (better) that a fragment shader can't and vice versa?
Metal has four different types of command encoders:
MTLRenderCommandEncoder
MTLComputeCommandEncoder
MTLBlitCommandEncoder
MTLParallelRenderCommandEncoder
If you're just doing graphics programming, you're most familiar with the MTLRenderCommandEncoder. That is where you would set up your vertex and fragment shaders. This is optimized to deal with a lot of draw calls and object primitives.
The kernel shaders are primarily used for the MTLComputeCommandEncoder. I think the reason a kernel shader and a compute encoder were used for the image processing example is because you're not drawing any primitives as you would be with the render command encoder. Even though both methods are utilizing graphics, in this instance it's simply modifying color data on a texture rather than calculating depth of multiple objects on a screen.
The compute command encoder is also more easily set up to do parallel computing using threads:
https://developer.apple.com/reference/metal/mtlcomputecommandencoder
So if your application wanted to utilize multithreading on data modification, it's easier to do that in this command encoder than the render command encoder.

How to use cuda Gaussian Blur in opencv [duplicate]

I understood that in OpenCV 3.0 the module GPU has been replaced by module CUDA, or better it has been split into several modules.
So cv::gpu::GpuMat has been replaced by cv::cuda::GpuMat, fine.
But what about the functions?
Where for example have the following moved to:
cv::gpu::GaussianBlurr ?
cv::gpu::Stream stream;
stream.enqueueConvert(...)
Apparently they are not under cuda module (eg. no cv::cuda::GaussianBlurr). Where can this functionality be found in OpenCV 3.0?
All CUDA-accelerated filters (Blur, GaussianBlur, Sobel, etc.) are located in cudafilters module: https://github.com/Itseez/opencv/blob/master/modules/cudafilters/include/opencv2/cudafilters.hpp
New API uses Algorthim-base approach:
cv::Ptr<cv::cuda::Filter> filter = cv::cuda::createGaussianFilter(src.type(), dst.type(), ksize, sigma);
filter->apply(src, dst);
The new approach helps to reduce memory allocations for internal buffers and reduce overhead from filter initialization stage.

Is there any equivalent function in the opencv gpu namespace to the function cvInvert from the cv namespace?

I'm trying to port an openCV application from the cv to the gpu namespace to take advantage of GPU optimizations and I can't find an equivalent function to cvInvert in the docs. Could you please tell me if such a function exists?
Opencv does not have an equivalent GPU invert function.
It would be in the gpu operations on matrices page but that page does not contain any functions that invert matrices.

Resources