How can I draw boundary around data points plotted using scatter3 function?

Hello all,
You may please see the data plotted using scatter function here followed by data in excel sheet here. We can just see a single object here but there may be hundred of such in a single figure. My task is to draw tight/collapsed boundary around these block of points. One solution is to fill 3x3 neighborhood around each pixel point, I can get a shape and can find the edges using canny edge detector. In this case, edges are zigzagged and couldn't find a straight longest line or a single continuous line around such shapes. Line may be straight enough to represent a boundary of this shape. I'm anxiously waiting for your help. Thanks!

1 Kommentar

Ali Gilani
Ali Gilani am 24 Mai 2014
Bearbeitet: Image Analyst am 24 Mai 2014
Any ideas how to address the above said task efficient ? I'm stuck. How can I find the corners of of this shape? Seeking for some help. Thanks!
Explaination about data:
1st and second column are the x and y values and we just plotted them. It turns out be a building's roof. Now I have to find the trace a boundary around this shape (around whole points, that are grouped together).
I'd really appreciate your assistance. Thank!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 24 Mai 2014
You can try convhull() or in 3D convhulln(). If you have an image, use bwconvhull().

7 Kommentare

I'm going to try suggested solution. I just have these pixel positions, can see in given data and don't have any image.
Thanks!
Ali Gilani
Ali Gilani am 24 Mai 2014
Bearbeitet: Image Analyst am 24 Mai 2014
I followed the guidelines and got the result (attached - convex Hull.png )
But I want to join only the outer most pixel positions to compactly form the boundary around shapes (contiguous pixel positions) as you can see the following link (edited in MS Paint - required.png ).
I would really appreciate any support from you guys.
Thanks!
If you want to treat this as an image, and each point is just one pixel away from its neighbors, then use bwareaopen() to get rid of small blobs. Then use bwboundaries().
binaryImage = bwareaopen(binaryImage, 50); % Get rid of blobs smaller than 50
binaryImage = imfill(binaryImage, 'holes'); % Fill in any missing dots.
boundaries = bwboundaries(binaryImage);
If you want to treat as isolated points, like an N by 2 list of coordinates, it's harder. You basically have to do the connected components labeling yourself. I'd recomment turning into an image by "setting" each pixel in an image if the coordinate is included. Then use the first approach
Your assistance is highly appreciated. Through your guidelines, I traced boundary of following actual input image and plotted the traced boundary using code
binaryImage = im2bw(imread('image.jpg')) ;
binaryImage = bwareaopen(binaryImage, 10);
[boundaries,L] = bwboundaries(binaryImage);
hold on
for k = 1:length(boundaries)
boundary = boundaries{k};
plot(boundary(:,2), boundary(:,1), 'black', 'LineWidth', 1)
end
In traced boundary image, outer boundary is undesirable and is not needed all. I even tried DoG method to trace the boundary of above input image. Can you help me how to get rid of this outer boundary.
Secondly, can you please guide how can I smooth the inner boundary around image and convert the zigzag effect (small boundaries) into a long big edge.
Invert the image and call imclearborder
grayImage = imread('image.jpg'); % Read in grayscale image.
binaryImage = grayImage < 128; % Central black region will be white now.
binaryImage = imclearborder(binaryImage); % Get rid of tick marks near edge.
You should have just one region after that.
It worked... Thank you dear! Can you please guide me, how can I smooth the boundary to make a longest edge and merge these small edges like best fitting line (to remove zigzag effect). So that instead of small many edges, I can use the longest edges only. One such morphed exemplary image attached Best fit lines.
There was a discussion here that talked about this paper: http://dip.sun.ac.za/~hanno/tw444/lesings/lesing_19.pdf on minimum perimeter polygons.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by