How is the pattern used in medianBlur in Opencv? - image-processing

I was reading about median filters in John C. Russ - The Image Processing Handbook, Sixth Edition, and in his book he describes the possible shape in the neighbouring pixels, which could be, for example a cross or square.
So I came across OpenCV medianBlur and was unsure about the pattern used. I would assume it is squared, but not sure. So what is the pattern implemented in OpenCV?

You are correct. It is squared.

Related

RoI cropping in Spatial Transformer Network

TL;DR: How does RoI cropping method from Spatial Transformer Network works?
Reading PyTorch Spatial Transformer Network tutorial I saw the network uses a special RoI pooling I haven't seen before called RoI cropping.
Reading the docs for the F.affine_grid and F.grid_sample did not explain so much what is happening there, so I tried reading the network's paper in hope to understand as well as some blog post on Faster RCNN elaborating on the method with pictures, but still no help.
I feel every source has different details and can't get the idea of what exactly is happening there, as good as I understand the normal RoI pooling and align methods.
Right now, this is the big picture in my head:
1. As usual, map the suggested RoI coordinates to the feature map space.
2. Normalize the coordinates to the range of [-1, 1] (I guess that's for the following affine transformation).
3. Calculate (using the method in the picture below) the transformation values.
4. Now, I assume we apply the transformation to the RoI pixels?
5. And finally, I assume we do an interpolation (i.e. bilinear interpolation) to the final coordinates.
Could someone briefly explain the whole process of the RoI cropping method? I feel I might be missing something.

Detect elliptical patterns with OpenCV [duplicate]

I am trying to detect elliptical kernels, in OpenCV using C++. I have tried obtaining Canny edges, and then using fitEllipse() function on the edges. Though this finds ellipses, the accuracy is horrid when the image is noisy, or if there are many edges.
I have realised that the way to go is detecting ellipses, and not fitting them. Maybe something like Hough circles, but for ellipses? I also do not know the length the ellipses could be, as it varies between images.
Can anybody help me get started on that? All related answers are very vague, and I just want pointers on where to start.
As you already got, you don't need ellipse fitting, but ellipse detection.
You can find in my other answer two papers with C++ code available. I'll report here for completeness:
L. Libuda, I. Grothues, K.-F. Kraiss, Ellipse detection in digital image
data using geometric features, in: J. Braz, A. Ranchordas, H. Arajo,
J. Jorge (Eds.), Advances in Computer Graphics and Computer Vision,
volume 4 of Communications in Computer and Information Science,
Springer Berlin Heidelberg, 2007, pp. 229-239. link, code
M. Fornaciari, A. Prati, R. Cucchiara,
"A fast and effective ellipse detector for embedded vision applications", Pattern Recognition, 2014 link, code
It's also fairly easy to port to OpenCV this matlab script with the implementation of the two papers:
"A New Efficient Ellipse Detection Method" (Yonghong Xie Qiang , Qiang Ji / 2002)
"Randomized Hough Transform for Ellipse Detection with Result Clustering" (CA Basca, M Talos, R Brad / 2005)
Another very interesting algorithm is:
Dilip K. Prasad, Maylor K.H. Leung and Siu-Yeung Cho, “Edge curvature and convexity based ellipse detection method,” Pattern Recognition, 2012.
Matlab code can be found here
Directly applying Hough Transform is not feasible for an ellipse, since you'll work in a 5 dimensional parameter space. This will be really slow, and not accurate. So a lot of algorithms have been proposed. Among the ones mentioned here:
Xie and Ji approach is quite famous and very easy (but still slow)
Basca et al. approach is faster, but may be not accurate
Prasad et al. approach is fast, and very accurate.
Libuda et al. approach is very fast and accurate
Fornaciari et al. approach is the fastest, but may be inaccurate in particular cases.
For the up-to-date bibliography for ellipse detection, you can refer to this page.

opencv MSER.detectRegions() vs findContours(): what's the difference?

I am building a generic text parsing algorithm for images.
I was running:
MSER.detectRegions()
vs
findContours(...cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
on a binary image. The results where the same.
I know MSER can be done on gray-scale but I wanted to go safer.
I need to select one of them and the findContours() takes less then half the run time MSER does.
Am I missing something?
What would you pick?
As already pointed out, it does not make sense to compute MSER on a binary image. MSER basically thresholds an image (grayscale) multiple times using increasing (decreasing) thresholds and what you get is a so called component tree like this here. The connected components which change their size/shape at least over the different binarizations are the so-calles Maximally Stable Extremal Regions (e.g. the K in the schematic graphic). This is of course a very simplified explanation. Please ask Google for more details, you'll find enough.
As you can see, thresholding an already thresholded image does not make sense. So pass the grayscale image to the MSER algorithm instead. MSER is a common basis for state-of-the-art text detection approaches (see here and here).

Detect a pattern highlighted by infrared light with openCV

For a project I've to detect a pattern and track it in space despite rotation, noise, etc.
It's highlighted with IR light and recorded with an IR camera:
Picture: https://i.stack.imgur.com/RJuVS.png
As on this picture it will be only very simple shape and we can choose which one we're gonna use.
I need direction on how to process a recognition of these shapes please.
What I do currently is thresholding and erosion to get a cleaner shape and then a contour detection and a polygon approximation.
What should I do then? I tried hu-moments but it wasn't good at all.
Could you please give me a global approach to recognize and track such pattern in space?
Can you choose which shape to project?
if so I would recomend using few concentric circles. Then using hough transform for circles you can easily find the center of the shape even when tracking is extremly hard (large movement/low frame rate).
If you must use rectangular shape then there is a good open source which does that. It is part of a project to read street signs and auto-translate them.
Here is a link: http://code.google.com/p/signfinder/
This source is not large and it would be easy to cut out the relevant part.
It uses "good features to track" of openCV in module CornerFinder.
Hope it helped
It is possible, you need following steps: thresholding image, some morphological enhancement,
blob extraction and normalization of blob size, blobs shape analysis, comparison of analysis results with pattern that you want to track.
There is many methods for blobs shape analysis. Simple methods: geometric dimensions, area, perimeter, circularity measurement; bit quads and others (for example, William K. Pratt "Digital Image Processing", chapter 18). Complex methods: spacial moments, template matching, neural networks and others.
In any event, it is very hard to answer exactly without knowledge of pattern shapes that you want to track )
hope it helped

OpenCV 2.2 PCA and EigenFaces

I just wanted to know if the cv::PCA::PCA constructor method in OpenCV 2.2 makes the substraction of the mean, or if I must pass my data already with the mean subtracted.
I tested both ways, but when visualizing eigenfaces neither of them are giving me good results but just a black screen. I have no segmentations faults or errors, I just don't get the eigenfaces visualization as in the papers.
I posted a complete example that shows how to use the PCA and display Eigenfaces here: PCA + SVM using C++ Syntax in OpenCV 2.2 (and on my page: http://www.bytefish.de/blog/pca_in_opencv).
It seems that they substract the mean within the PCA functions (i went to see the declaration of cv::PCA). Anyway I can't get eigenfaces visualization, it is just a black window. What I thought was that they weren't normalized, but no, I printed the L2 norm of each eigenvector and it is exactly 1.
I think to get eigenfaces you need to project the PCA eigenvector to an image.

Resources