Separating and extracting data using edge detection
9 ビュー (過去 30 日間)
古いコメントを表示
I want to use edge detection to separate my data and put the “pieces” into separate matrices.
I begin with a large matrix (~1000x1000). Within it, I have data points that are clustered together and several cells of "NaN" that separate the clusters from each other. After changing the NaN values to a very big negative number and using the "mat2gray" function, I run the "edge" function. Viewing this shows that the clusters are well outlined.
What I would like to do now, knowing where the edges of the clusters are, is create matrices containing the original data of a single cluster for each cluster.
My problem is that I do not know how to use the output of the edge function to accomplish that. I would appreciate any advice, including if this is an inefficient/impossible/dumb way to get what I want. My motivation for using edge detection is that the cluster placement and spacing is not constant and the "pattern" of the clusters change from data set to data set.
採用された回答
J. Alex Lee
2020 年 8 月 2 日
since it appears you have the image processing toolbox (access to "edge"), have you looked into "regionprops"?
If you're labeling the edges with extreme numbers, it seems reasonable to me that you can end up with a BW "mask" of the clusters of interest (binarize your gray image). Then I think regionprops will do what you want.
If I'm off base, maybe you can post an image of the gray images you're ending up with.
その他の回答 (1 件)
Image Analyst
2020 年 8 月 2 日
Attach your image in a .mat file. Do the nans run in between the pixels you want in a cluster? If not, simply do this
mask = ~isnan(yourImage);
boundaries = bwboundaries(mask);
If you have thin threads of nan's running through your blobs, then you can do a morphological closing to close up the gaps:
mask = ~isnan(yourImage);
radius = 5; % Bigger number will connect more nearby blobs, smaller number will connect fewer.
se = strel('disk', radius, 0);
mask = imclose(mask, se);
boundaries = bwboundaries(mask);
3 件のコメント
Image Analyst
2020 年 8 月 3 日
So in the sample image below:
There are two clusters, one with 3 blobs and one with 4 blobs. His main goal is to "create matrices containing the original data of a single cluster for each cluster" so I guess that he would want two images, one with the top cluster and one with the bottom cluster. Now each segmented blob has an edges, shown in red. And each cluster has an edge, or could have several of them. The green one I show is like the convex hull of the cluster. However I don't see how getting the edges of either each blob or clusters of blobs will help in getting the two images. I tihnk this is just like we see all the time where novices can see edges in an image and then that the edges should be detected because they will somehow help in subsequent processing. In our experience here, that is rarely the case. Now regionprops can get the coordinates of all the white pixels, and bwboundaries can get the red boundaries, and there are ways to get the green boundaries. There are several ways to determine the clusters in the green boundaries, like kmeans, dbscan, bwdist, etc. I'm not going to do more without knowing/seeing the actual image since it could be a lot of work for some situation that does not apply in his situation. In fact, I'm not even sure the cropping of the clusters into new images is even needed. Maybe the clusters need to be identified but I don't see that cropping is needed. Plus I don't know what measurements need to be made on the clusters - he never said what measurements needed to be done once each cluster is isolated.
Finally, since we last heard from KF on July 14th (3 weeks ago!), I don't even believe that he's interested in this question anymore so any further work on it would be a complete waste of our time.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!