Find symmetry point/center point in an irregular image - python

I am trying to find symmetry lines or points in my image
My main aim is to find the center of this contour. But I can't use thresholding, so can't use OpenCV contours.
So my next guess it to find symmetric point in my image and hopefully that will correspond to the center of this contour. Any other idea to find center of this contour is also appreciated, something which doesn't involve thresholding as I can't give parameters to user.
I tried finding centroid using cv moments but that didn't give me good results.
I tried using hough circle detection, but it couldn't detect this as circle.
I am using python and OpenCV.

The question is rather vague, lacking adequate sample images and there is little feedback to comments, so it is a stab in the dark as whether you are having difficulty separating the objects, or finding their lines of symmetry, but I wanted to point out that ImageMagick does a pretty good job of separating the objects using the algorithm described here.
Here it is from command line with dithering suppressed:
magick IuOWe.jpg +dither -colors 3 result.jpg
And here with initial blurring:
magick IuOWe.jpg -blur 0x5 +dither -colors 3 result.jpg
Of course you can use similar techniques with OpenCV, or scikit-image as you have tagged Python - it is just quicker to demonstrate my avenue of thought using ImageMagick.

Related

Extracting contours from high temperature image

I want to extract the outline of an object within a furnace, here is the image:
I have tried various techniques to process the image but I have failed, the technique that gives the best image of the object is CLAHE as seen here:
Simple normalization:
I have tried Canny, Sobel, dilating, eroding and morphing but I cannot seem to get them to work harmoniously to allow me to extract the contour I want ( the contour surrounding the object in the furnace).
Any suggestions would be appreciated.
Histogram equalization followed by strong Gaussian filtering in the horizontal or vertical directions will enhance the near-horizontal and near-vertical edges (separately). That's about the best you can do. (Maybe try Hough on these.)
Also notice that the specialized edge fitters as found in typical gauging libraries can help you if the geometry is roughly known.

How to close a contour with OpenCV when dilating isn't enough

I have been looking to close contour for shapes that are similar to circles or rounded objects.
I found a very interesting answer here.
I thought my problem was solved until I tested with different images.
This is my mask from OpenCV canny AFTER dilating. As you can see, there is a big gap at the bottom.
If the shape was a circle, I could try to recreate the circle, but the thing is the shape could be different. I could look like a cucumber or a rugby balloon.
I wonder if it's actually possible to connect the contour without doing a straight line, which will make me lose a lot of information.
Approximating the "curveness" or "straightness" according to the neighbor?

How do I split a shape with conected pixels in to two parts in a binary image

My goal is to draw a rectangle border around the face by removing the neck area connected to the whole face area. All positive values here represent skin color pixels. Here I have so far filtered out the binary image using OpenCV and python. Code so far skinid.py
Below is the test image.
Noise removals have also been applied to this binary image
Up to this point, I followed this paper Face segmentation using skin-color map in videophone applications. And for the most of it, I used custom functions rather than using built-in OpenCV functions because I kind of wanted to do it from scratch. (although some erosion, opening, closing were used to tune it up)
I want to know a way to split the neck from the whole face area and remove it like this,
as I am quite new to the whole image processing area.
Perform a distance transform (built into opencv or you could write by hand its a pretty fun and easy one to write using the erode function iteratively, and adding the result into another matrix each round, lol slow but conceptually easy). On the binary image you presented above, the highest value in a distance transform (and tbh I think pretty generalized across any mug shots) will be the center of the face. So that pixel is the center of your box, but also that value (value of that pixel after the distance transform) will give you a pretty solid approx face size (since it is going to be the pixel distance from the center of the face to the horizontal edges of the face). Depending on what you are after, you may just be able to multiply that distance by say 1.5 or so (figure out standard face width to height ratio and such to choose your best multiplier), set that as your circle radius (or half side width for a box) and call it a day. Comment if you need anything clarified as I am pretty confident in this answer and would be happy to write up some quick code (in c++ opencv) if you need/ it would help.
(alt idea). You could tweak your color filter a bit to reject darker areas (this will at least in the image presented) create a nice separation between your face and neck due to the shadowing of the chin. (you may have to dial back your dilate/ closing op tho)

Removing text while processing the image

I am working on an application where I need feature like Cam Scanner where document is to be detected in an image. For that I am using Canny Edge detection followed by Hough Transform.
The results look promising but the text in the document is creating issues as explained via images below:
Original Image
After canny edge detection
After hough transform
My issue lies in the third image, the text in original mage near the bottom has forced hough transform to detect the horizontal line(2nd cluster from bottom).
I know I can take the largest quadrilateral and that would work fine in most cases, but still I want to know any other ways where in this processing I can ignore the effect of text on the edges.
Any help would be appreciated.
I solved the issue of text with the help of median filter of size 15(square) in an image of 500x700.
Median filter doesn't affect the boundaries of the paper, but can help eliminate the text completely.
Using that I was able to get much more effective boundaries.
Another approach you could try is to use thresholding to find the paper boundaries. This would create a binary image. You can then examine the blobs of white pixels and see if any are large enough to be the paper and have the right dimensions. If it fits the criteria, you can find the min/max points of this blob to represent the paper.
There are several ways to do the thresholding, including iterative, otsu, and adaptive.
Also, for best results you may have to dilate the binary image to close the black lines in the table as shown in your example.

Principles to draw a contour

I want to know the principles to draw a contour, for example, which lib they use, I mean the most original one ,not matplotlib or opencv.
Like in matplotlib or opencv, they use what kind of method to draw a contour.
Thank you for answering.
In documentation of Opencv mentioned this function implements the algorithm of:
Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by
Border Following. CVGIP 30 1, pp 32-46 (1985)
so you can read about this algorithm and discover the principles of draw a contour! and see the wiki link of Suzuki-Kasami algorithm here.

Categories

Resources