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/
Related
I'm trying to use Hough circle detection method to find all the circle as shown in the image(shown in image 1 and 2). Initially, I used canny and findContour method (shown in image 3). I'm still unsure which method will be more suitable.The problem with the canny and findContour method was that it didn't find all the circles as well as getting lot of noise. But when using the Hough circle detection, the circle is sometimes catching the outer perimeter instead of the inner as shown in image 2.
The canny+findcontour methods finds the circle contour well but has a lot of noise whereas Hough circle works well but the circles sometimes blends with the outer circle.
Hough circle
Hough circle-zoomed in
canny + findcontour method
I think you can get better results if you pre-process the image. First apply Otsu thresholding, if that doesn't work well use a manual value for threshold. After that use the cv.erode() function to get a crisp boundary. Then try to apply the Hough circle transform.
If performance is not an issue, another interesting thing would be to to look at Holistically Nested Edge Detection and then apply Hough circle transform.
Also have a look at the following:
https://www.learnopencv.com/filling-holes-in-an-image-using-opencv-python-c/
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html
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)
I have to remove some lines from the sides of hundreds of grayscale images.
In this image lines appear in three sides.
The lines are not consistent though, i.e, they appear above, below, left and/or right side of the image. And they are of unequal length and width.
If you could assume that the borders are free of important information, you may crop the photo like this:
C++ code:
cv::Mat img;
//load your image into img;
int padding=MAX_WIDTH_HEIGHT_OF_THE LINEAS_AREA
img=img(cv::Rect(padding,padding,img.cols-padding,img.rows-padding));
If not, you have to find a less dumb solution like this for example:
Findcontours
Delete contours that are far from the borders.
Draw contours on blank image
Apply hough line with suitable thresholds.
Delete contours that intersect with lines inside the image border.
Another solution, assuming the handwritten shape is connected:
Findcontours
Get the contour with the biggest area.
Draw it on a blank image with -1(fill) flag in the strock argument.
bitwise_and between the original image and the one you made
Another solution, asuming that the handwritten shape could be discontinuity :
Findcontours
Delete any contour that its all points are very close to the border (using euclidian distance with a threshold)
Draw all remaining contours on a blank image with -1(fill) flag in the strock argument.
bitwise_and between the original image and the one you made
P.S. I did not touch HoughLine transform since I do not about the shapes. I assume that some of them may contain very straight lines.
I'm trying to create app for applying Affine transform only for some part of image(non rectangular).
http://s29.postimg.org/k45fwbmsn/Untitled.png
Is there exist any way, to transform only selected(visible) part of the image?
I'm certain the overall transformation you described (only on part of an image) is not affine. So it isn't as easy as applying a matrix multiplication to some vectors.
But of course, there are ways to define algorithms that detect black rectangles and apply an affine transformation to the coordinates of detected rectangles. With the transformed coordinates you can draw a new quadrangle. Note: After an affine transformation it does not need to be a rectangle anymore.
Btw. you're contradicting yourself:
transform only for some part of image(non rectangular).
vs
to transform only black rectangle
I'd propose you clarify the following points about your input and expected output:
Which of the contradicting transformations do you want: Only rectangles or everything but rectangles?
Is it binary black-and-white, gray-level or colour image? This is a question of simple to complex input with quite some impact on the algorithm.
Is the image noiseless, i.e. is it true black or all sorts of really dark colours? For true black you might be able to apply a simple heuristic to detect the rectangles. If it's a noisy image you need to think about image filters/improvements and colour space transitions.
Are the rectangles the only "black" areas in your image?
Are the rectangles in parallel to x and y axis? Again this is simple heuristic vs pattern recognition.
Is the number of rectangles known? Are multiple rectangles related (in size, proportions, parallel) to each other?
What is to happen on borders or with image parts revealed by moving/shrinking the rectangles?
I'll edit the answer, when you provide the required information in your question.
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.