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

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

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:

Find contour without negative area inside shape

As a follow-up question to finding contiguous black pixels in image, I use OpenCV's findContours() to detect shapes of black on white (I invert the colors for the function to work better). In the images below, OpenCV detects the outer shape of the "g" and the inner bowl as different shapes:
I could use the hierarchy to discard shapes inside other shapes, but I would rather avoid it in case OpenCV detects an overarching contour around the whole image. Does findContours have some tuning that cause it to find only contiguous pixels and not the inside negative shape?

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

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

How to remove lines from the sides in opencv?

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.

Affine transform of non rectangular part of the image

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.

Resources