How to remove white pixels from Binary image using Morphological Operators? - opencv

I am working with images of rocks. Here I have to segment them. I get a depth image as input.
After thresholding the image, there are some white pixels which I tried to remove but to no avail.
The methods I have used :
1. Bilateral Filter (not a morphological operator)
2. Closing
3. Erosion
The result are shown in the images below.
My task is to remove those white pixels INSIDE THE ROCKS using morphological operations. If the white pixels are not removed it affects my algorithm later(distance transform).
Is there a way using only morphological operations?If not, is there any other way?
1.Bilateral Filter
2.Closing
3.Erosion
4.Original Depth 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:

Extracting near-border elements of an image using logical operators and/or morphological transformations

Using logical operators (intersection, difference...etc) and/or morphological transformations (erosion, dilation and skeletonization) and given an image as the one below (original image), how can all the elements which are cut by the image's frame be extracted ? in order to keep only whole ones.
Original image
Intended result:
Near-border elements
Whole elements
I have tried intersecting the original image with another representing only the frame, and then applying a dilation on the intersection (though it doesn't seem possible to me to reconstitute the elements by dilating lines) and here are the results:
An image representing only the frame Intersection between the frame image and the original image Dilation of the intersection
(The dilation was tired with circular and square structuring elements of sizes ranging from 3X3 to 51X51)
Thank You.
This is morphological reconstruction (flood-filling). Marker - border of image, mask - original image.
https://www.mathworks.com/content/dam/mathworks/tag-team/Objects/m/64199_91822v00_eddins_final.pdf

OpenCV: How to closes edges in a binary image

I am trying to perform image segmentation on the following image of brain tissue:
The following is what the segmented result should look like:
I have the following result which I have obtained after applying thresholding, morphological transformations and contour area filtering (used to remove noise in the image) to the original image:
Result before contour filtering:
Result after contour filtering:
However, in my result, some of the black edges got separated/broken apart. Is there any simple method that I can use to close the small gaps between some of the edges.
E.g. is it possible to fill the white spaces between the edges circled in red with black?
Any insights are appreciated.
The easiest method would be to attempt to use Morphology. You simply perform a dilation operation followed by an erosion operation.
The following script uses opencv's Morphology function:
import numpy as np
import cv2
folder = 'C:/Users/Mark/Desktop/'
image = cv2.imread(folder + '6P7Lj.png')
image2 = cv2.bitwise_not(image)
kernel = np.ones((8,8),np.uint8)
closing = cv2.morphologyEx(image2, cv2.MORPH_CLOSE, kernel)
closing = cv2.bitwise_not(closing)
cv2.imshow('image', closing)
cv2.waitKey(0)
This is the results:
Most of the edges were connected. I'm sure you can further play with the function's kernel to get better results (or even use openCV's separate dilatation and erosion function to get ever more control).
Note: I add to invert the image before performing the operation because it treats white pixels as positive and black as negative, unlike your image. In the end it was inverted again to return to your format.

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)

How to detect large galaxies using thresholding?

I'm required to create a map of galaxies based on the following image,
http://www.nasa.gov/images/content/690958main_p1237a1.jpg
Basically I need to smooth the image first using a mean filter then apply thresholding to the image.
However, I'm also asked to detect only large galaxies in the image. So what should I adjust the smoothing mask or thresholding in order to achieve that goal?
Both: by smoothing the picture first, the pixels around smaller galaxies will "blend" with the black space and, thus, shift to a lower intensity value. This lower intensity can then be thresholded, leaving only the white centres of bigger galaxies.

Resources