What Operations can I use to extract the Hard Edges/Lines from this image - opencv

I'm able to detect the main hard edges in an image quite well using morphological gradient - see below image. How can I process this image to just extract the hardest/whitest edges? Thresholding either results in a very noisy image or hard edges lacking in detail/too eroded.
My thresholding result:
My goal is something like this:
*Note: I'm attempting to use the Morphological Gradient operation as a light weight way to detect the hard/main edges in an image. The OpenCV code will run on a raspberry pi robot so I'm trying to be quite efficient with my resources - thus I'm using Morphological Gradient as opposed to Canny or etc.
Original image:

I initially said Difference of Gaussians but you already had a better threshold image.
So I took the first image as input and performed Otsu Threshold. I used the image obtained from the function cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) to detect lines.
Lines were detected using cv2.HoughLinesP()
My (not so good) result:
You have the option of drawing the lines onto your original image.

Related

Using image morphological techniques, locate the broken locations

Can someone please guide the steps/the operation to be performed to construct this image and detect the broken fence position of the Image.
Thresholding the image to a binary image : to convert the input image to a binary image
Inverting the image : inverting it to get a black background and white lines
Dilation with SE one unit of the fence structure
Apply Erosion
Bitwise-and masks together: retrieve the original back- and foreground the image is inverted by subtracting the bitwise_or from 255
Constructed Image - Original Image will give us the position of the broken fence
Will this solution work ?
Depends what you call locate.
After large horizontal erosion and binarization:

OpenCV: Image segmentation of greyscale image

I have the following EM image of brain tissue and I am trying to segment the neurons.
The following is what the segmented result should look like:
I am trying to do Watershed segmentation to segment the image. However, when trying to create a binary mask (using simple thresholding in OpenCV), I do not get a very good mask at all because of the dark round features in the image (circled in red).
Here is the mask I got below:
# code used to get the mask
img_smooth = cv2.GaussianBlur(img_grey, (21,21), 0)
retval, threshold = cv2.threshold(img_smooth, 125, 255, cv2.THRESH_BINARY)
Is there any way that one can replace these dark round features with grey using simple techniques like filtering/thresholding? Or is there no way to remove these round dark features through simple techniques and machine learning methods are necessary to accomplish this task? Any insights are appreciated.

OpenCV : Modifying inpainting to achieve proper blur in image

I am trying to do some image processing for which I need to remove the facial features like eyes, nose, lips etc.
I have the following contour points
I am doing inpainting on this image::
Now I have to remove the facial features namely eyes, nose, lips and have the skin in place or that. The thing is that I don't have to do just for this image but for a general image that the user uploads.
I am trying using inpainting but it does create some problem, especially around lips where its having beards in neighbouring pixels and it gives a blackish output like this ::
I tried different contour points and shapes but somewhere or the other its causing problem mainly because of hair or beards. So how to achieve what I am trying to?
Code ::
Photo.inpaint(finalImage,imageROIGRAY,imageROIDest,8,Photo.INPAINT_NS);
I have done dilation also on the mask, but doesn't work.
Showing mask for one of the shape formed using the contour points ::

Detect triangles, ellipses and rectangles from an image

I am trying to detect the regions of traffic signs. Using OpenCV, my approach is as follows:
The color image:
Using the TanTriggs Preprocessing get rid of the illumination variances:
Equalize histogram:
And binarize (Cv2.Threshold(blobs, blobs, 127, 255, ThresholdTypes.BinaryInv):
Iterate each blob using ConnectedComponents and get the mean color value using the blob as mask. If it is a red color then it may be a red sign.
Then get contours of this blob using FindContours.
Simplify the contours using ApproxPolyDP and check the points of each contour:
If 3 points then triangle shape is acceptable --> candidate for triangle sign
If 4 points then shape is acceptable --> candidate
If more than 4 points, BBox dimensions are acceptable and most of the points are on the ellipse fitted (FitEllipse) --> candidate
This approach works for the separated blobs in the binary image, like the circular 100km sign in my example. However if there is a connection to the outside objects, like the triangle left bottom part in the binary image, it fails.
Because, the mean value of this blob is far from red!
Using Erosion helps in some cases, however makes it worse in many of the other images.
Using different threshold values for the binarization also works for some, but fails on many; like the erosion.
Using HoughCircle is just very slow and I couldn't manage to get good results playing with the parameters.
I have tried using matchShapes but couldn't get good results.
Can anybody show me another way the achieve what I want (with a reasonable computational time)?
Any information, or code in any language is wellcome.
Edit:
Using circularity measure (C=P^2/4πA) or the approach I have described above, triangle and ellips shapes can be found when they are separated. However when the contour is like this for example:
I could not find a robust way to extract the triangle piece. If I could, I would check the mean color, and decide if its a red sign candidate.
Sorry, I don't have the kudos to comment, but can't you use the red colour?
import common
myshow = common.myshow
img = cv2.imread("ms0QB.png")
grey = np.zeros(img.shape[:2],np.uint8)
hsv = cv2.cvtColor(img,cv2.COLOR_mask = np.logical_or(hsv[:,:,0]>160,hsv[:,:,0]<10 )
grey[mask] = 255
cv2.imshow("160<hue<182",grey)
cv2.waitKey()

Finding ROI for a periodic repetative fringe pattern

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)

Resources