Finding ROI for a periodic repetative fringe pattern - opencv

I am trying to detect ROI for a fixed repetitive pattern in an image using opencv C++.
The ROI which I am trying to find - is shown with red boundary as shown in the pic:
I tried canny edge detection after blurring but it detects edge of the vertical/horizontal black and white lines. This is not something I am trying to detect.
What is the best approach to my problem?

Since you're starting with a binary image you could use
findContours()
to get the contours for the individual strips. Since there are a couple of solitary pixels from noise you should then filter for size using
contourArea(contour)
and merge the points of all contours meeting your size criteria into a combined contour. Then get the bounding box for the combined contour:
boundingRect(combinedContour)

Related

How to extract the paper contours in this image (opencv)?

I'm trying to extract the geometries of the papers in the image below, but I'm having some trouble with grabbing the contours. I don't know which threshold algorithm to use (here I used static threshold = 10, which is probably not ideal.
And as you can see, I can get the correct number of images, but I can't get the proper bounds using this method.
Simply applying Otsu just doesn't work, it doesn't capture the geometries.
I assume I need to apply some edge detection, but I'm not sure what to do once I apply Canny or some other.
I also tried sobel in both directions (+ve and -ve in x and y), but unsure how to extract these contours from there.
How do I grab these contours?
Below is some previews of the images in the process of the final convex hull results.
**Original Image** **Sharpened**
**Dilate,Sharpen,Erode,Sharpen** **Convex Of Approximated Polygons Hulls (which doesn't fully capture desired regions)**
Sorry in advance about the horrible formatting, I have no idea how to make images smaller or title them nicely in SOF

Find shapes on white background. Thinning the lines

I have the following image as a test image:
I attempt to find the shapes on the image (and other images). My approch right now is the following:
Gaussian blur with a 3x3 kernel
Canny edge detection using
list (to get all shapes)
Morphology with MorphOp.Close to close
the edges
FindContours to find contours
Iteration of each contour:
Find ApproxPolyDP
Find ConvexHull
Discard if
hull size < 2, approx area < 200 or hull size > 50000, or arclength
of the approx < 100
Draw convexhull
This method yields the following images where the convex hulls are drawn:
This is almost perfect, but notice that the lines are seen as a contours events->suppliers and events->documents). When looking at the edge information, it becomes apparent why this is so:
The lines are detected as a contour. How could I prepare/find the shapes so the lines are not detected? I though of some thinning algorithm, but since I also work on real life images it is difficult to find a threshold that works. Here is an example of a real life image where thinning is difficult to do because thinning typically requires the images to be monochrome in black and white.
How would you do it? Is there some method to determine if the contour/convex hull is a line, rectangle or something like this?
I ended up using a mix of overlapping test and convexity scan. The convexity scans for the error between the convex hull and the actual contour. If this error exceeds a certain amount, the hull is ignored. The overlapping simply use bitwise and to detech if two convex hull's overlap. If they overlap more than 95% percent, one of them is ignored.

Finding a defective Corner[circled] from contours

I want to find the corners of a object & detect if there is a cut in the corner. The Real Image is so Big & it consist of lot of noise inside the Contour Area. So far I've tried...
1)find the contours
2)approximate the contour to find the approximate corners points
3)crop each corner image & compare it with cvMatchShapes() Rotated # Corners.
But the results was not accurate & i need some guidance.Here is the sample canny output image for which i wanna detect the Cut which is CIRCLED. Also in real Image I'm getting lot of noise in the canny output so Pls suggest me how to detect this shape defect at Corners.
![enter image description here][1]Regards, Balaji.R
http://answers.opencv.org/question/25730/finding-a-defective-cornercircled-from-contours/
after you do the step 3, you may want to do hausdorff distance. OpenCV function can be found here. I think hausdoff distance best suites your requirement. Find the distance between the corners and if the distance is more than a certain value, then it is defective. It can also take care of noise upto certain extent.

Segmenting circle-like shapes out of Binary Image

I have several binary images and my task is to segment circle-like shape. The circles are not perfect rounded circle, but all of them will look like circle. Here are some example images and what I need:
As you can see from above, the left images are original images, and the right images are what I need to do. The circles intersect with other shapes, but I only want the circle, as indicated in red. The imaginary lines to close the circle will be required. What can I do in this case in Image Processing?
EDIT: in case, the image above is broken, here: http://imageshack.us/photo/my-images/835/circleonly.jpg/
Do you know the radii of the disks you are looking for?
If yes, morphological openings (erosion then dilation) would be straightforward, and very fast. The result using Mathematica:
Opening[img, DiskMatrix[15]]
If not, as other proposed, computing the contour image and then using the Hough transform would be a method worth pursuing. The image just above shows the contour image.
You can use hough transform, first you need is the edge image then you use a hough transform like you can see in this papers
http://www.cis.rit.edu/class/simg782/lectures/lecture_10/lec782_05_10.pdf
http://www.sci.utah.edu/~gerig/CS6640-F2010/FINALPROJECT/Ballard-GHT-1981.pdf
http://www.sciencedirect.com/science/article/pii/003132039290064P
http://www.markschulze.net/java/hough/

Using OpenCV to detect clothing buttons on a piece of paper

I have no background in computer vision, but I was curious to know how I could use OpenCV library to achieve the following:
I have a jar of spare buttons, assorted in colour, style and diameter. For the most part they are circular. I evenly scatter them on a piece of white paper, and under good lighting, take a fairly high resolution picture with your average digital camera. How would I got about slicing this image to grab each button individually as a separate object/image?
Thanks in advance.
Two possible ways:
1) Using the circle hough transform
You run some edge detector (canny/sobel) and then the circle hough transform. You'll get the circles.
2) Using contours
Seperate the button and background using thresholding. Detect contours in this thresholded image and you have the buttons!
Articles that might help:
Contours: http://aishack.in/tutorials/an-introduction-to-contours/
Thresholding: http://aishack.in/tutorials/thresholding/
Hough circles: http://aishack.in/tutorials/hough-circles-in-opencv/
Disclaimer: Those are links to my website.
I think the simplest thing you could try is: run the Canny edge detector and apply a Hough transform to detect circles and generate a separate image from each of the circles.
I've been doing some dish recognition and it worked pretty good. do this:
Do some thresholding (buttons should be shiner than background) to leave only the buttons,
then cvFindContours
for each contour:
run cvFitEllipse, it will return you both axis (a,b) of the fitted ellipse.
check that the area of an ellipse PIab is similar to the Area of the contour using cvContourArea and also that both axis are similar a = b. (this will leave only circles)
then you can do whatever you need.
printContour, using cvPrintContour, use cvMinAreaRect2 to get button bounding box, etc
Hough transform is also possible but it is quite more expensive.

Resources