Separating and extracting data using edge detection

9 ビュー (過去 30 日間)
K F
K F 2020 年 7 月 14 日
コメント済み: K F 2020 年 8 月 3 日
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.
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 8 月 2 日
Have you looked Hit & Miss Trasformation?

サインインしてコメントする。

採用された回答

J. Alex Lee
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 件のコメント
K F
K F 2020 年 8 月 3 日
Thank you! Though I’ve moved on from this problem, your answer is exactly what I did. I binarized the image and determined the bounding boxes using regionprops. I then cropped the original image using the bounding boxes and created a structure where each element is a cluster.
I’m including the code below in case it is of use to anyone in the future (it was drawn heavily from ImageAnalyst's Image Segmentation Tutorial). I apologize for not updating my question earlier. Nevertheless, thank you for your time and expertise.
% this code is drawn heavily from Image Segmentation Tutorial by Image Analyst
gray_img=mat2gray(Raw_data);
binary_img=imbinarize(gray_img);
cluster_boundaries= regionprops(invBinImg, leveled_data, 'BoundingBox');
boundingbox=table2array(struct2table(cluster_boundaries(:,1)));
% Put values from leveled data into sub structures based on boundaries
cropped_img_struct=struct([]);
for i = 1:length(boundingbox(:,1))
cropped_img_struct(i).f=imcrop(Raw_data,boundingbox(i,:));
end

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
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
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.
K F
K F 2020 年 8 月 3 日
Thank you for your answers, I appreciate your time and expertise. You're right that I have moved on from this problem. I apologize; in the future I will remember to update my questions.
@Image Analyst I want to especially thank you for your Image Segmentation Tutorial, which I came across after posting this question. I used it as a guide because your segmentation of the individual coins was essentially a more advanced version of what I was trying to do.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by