Can I split a contour image in subregions? - image-segmentation

I have an image with some contours:
I want to segment the sections that appear around those contours, ideally based in the distance among the adjacent lines. As in the image below, I need to split it in subregions as the ones red and pink colored. Does anybody know an algorithm for that task?

Related

Image segmentation (OCT)

My image is something like below:
I want to be able to draw 2 layers: (1) red line on top of 1st layer, but (2) blue line in the middle of 2nd layer
I am using OpenCV. but any languages/advice are welcomed.
You can do the following:
Small closing in order to reconnect the small separated components/patterns.
Small opening in order to remove the small isolated components/patterns.
Skeletonize (or median axis)
Pruning in order to remove the small branches.
You will then get a skeleton for each pattern. It will be close to the lines you want to draw. But it will be a little bit irregular, so you can interpolate it.
[EDIT] if you need the red line on top of the edge, a solution is to:
Extract the pattern contour
Keep only the pixel on top.
Algorithmically, it can be achieved doing this: for each X coordinate on the top border, go down the image vertically until you meet the first non-null pixel. If your image is NxM, you must have N pixels in your solution.
If you want to regularize/smooth the result, you have two solutions:
Transform the contour as a parametric function and smooth it.
Do an interpolation (spline?)

how to include a dark border to bright segmented image?

I have an image like this.note that the regions are not perfectly shaped.it is rectangular like region and ellipse like region. I have segmented the ellipse like region using some algorithm.segmented region is bright one.the border (red rectangle) is dark one
finally i must get red rectangular like region
can you suggest any algorithm to perform this
I see that you have done some real progress on your segmentation. Because you already have an idea of the location of elements you want to segment, you should use a watershed with constraints/markers:
Your actual segmentation represents the inner markers.
You dilate it with a big structuring element (bugger than the inter disk space).
You take the contour of the dilation, and that's your outer markers.
You compute the gradient of the original image.
You apply the watershed on the gradient image, using the markers you have just computed.
[EDIT] As the segmentation you provided does not match with the original image (different dimensions), I had to simulate roughly a simple segmentation, using this image (the red lines being the the segmentation you already have). And I got this result.

crop an image into several rectangles

I need to automatically process grayscale images like this and crop them into rectangular tiles. I used contour() to find the edges but how can I crop the image using the result of contour ?
Thanks a lot !
Assuming your image is already double grayscale (otherwise use im2double or rgb2gray), you can create a simple binary mask using:
IM %your image
M=IM>.5
Which means the mask contains a true for all values larger than .5. To select these pixels, use:
IM(M)
To select the opposite set, use:
IM(~M)
I think the basic algorithm would go somewhat like this:
1) recognize all horizontal lines
2) recognize all vertical lines
3) create a grid using all the lines from (1) and (2) - this will create more rectangles than you ultimately want, but each rectangle will be a single color
4) combine rectangles that are the same color and adjacent in one direction
5) combine the results of (4) in the other direction, possibly splitting some of the earlier combinations to come up with more a more optimal solution (e.g. in your example the two white rectangles in the first row and the three in the second row could be combined into a group of 2x2 rectangles by splitting the three into 1+2, giving you a 2x2 and a 1x1 rectangle, rather than a 2x1 and a 3x1).

how to do line fitting multiple lines MATLAB?

I'm trying find all straight lines in an image which is border. for example,stamps have four edges and I have already find those edges by edge function in MATLAB. But there is a problem that they are not real straight line. so I need to use line fitting to get all four borders. But polyfit function can only fit one line at one time. Is there any solutions that can fit all lines at one time.
for example:here I upload some pictures,the image with red lines is what I want. Please be ware I need four separate lines.
Judging from the image you won't be trying to smooth some lines, or fill in the gaps. Instead it looks more like you need to put your image in the smallest possible box.
Here is an algorithm that you can try:
Start from all 4 corners.
'walk' one of the corners inwards and determine if all points are still within four corners
If so, save this corner and go to step 2, else go to step 2
Keep repeating step 2 and 3 till you have a steady solution.
Are you trying to get rid of the perforations? In that case I would suggest using thresholding to segment out dark areas of the image, and then using regionprops to get their bounding boxes. Then you can figure out the largest rectangle that excludes them.

how to fill the empty space inside an image generated by matlab function "scatter"

My image is a 2D surface of a protein, and I use matlab function "scatter" to display the image, so there are some white empty spaces in it.
I want to fill them with colors,but the question is that the points have different colors, some are red and some are orange(point color is decided by its RGB value).
So I wanna assign the color of the white space similar to their corresponding neighbors.
the original work i did is to extract the edge of the polygon first,which helps me detect if the point is inside the polygon or not, because I am not assigning colors to white spaces that are outside the polygon.
And then simply scan the whole image pixels one by one to check if the pixel is the white, if so, I just assign the neighbor color to it,like what i said, I have to check if the pixel is inside the polygon or not every time.
But the speed is really slow, and the result is not good enough,could anybody give me some idea on it ?
I have the 2D scatter points image and also the 3D structure.Each point in 2D can find one
counterpart in 3D, I don't know if this information would help.
After an erosion with a disk kernel(7x7) such as and then a bilateral filter:
PS: if you have the 3D points structure, upload it somewhere and post a link