0

I have an image, and perform K-means-based segmentation against is using slic method. The code and result are attached. My question is that How can I extract the information for each segmented patch, such as its location, area, label, or related pixel values, etc.

segments = slic(img, n_segments = 250, sigma = 5,compactness=0.1)

enter image description here enter image description here

As advised, I used props = regionprops(segments) to extract the segmented patches. It turns out that props only has 249 elements instead of 250 as I setup in slic method. what causes the mismatch here?

user288609
  • 12,465
  • 26
  • 85
  • 127

1 Answers1

0

You can use skimage.measure.regionprops. Note: SLIC currently returns values in [0, ..., n_labels-1], but regionprops ignores 0, so you should add 1 to the output of SLIC.

Juan
  • 5,433
  • 21
  • 23
  • Hi Juan, thanks for your answer, i have updated my original post. The result of regionprops only gives 249 elements instead of 250 as I expected. is this what you were referring to in your answer. Please clarify. Thank you. Moreover, if I want to get the average pixel value of each segmented patch, should I use mean_intensity in the output? Thanks. – user288609 Oct 06 '19 at 04:51
  • you should use `segments = slic(...) + 1`, then `regionprops(segments, intensity_image=img)` yes, use `regionprops[i].mean_intensity` for each i, as well as any other properties you are interested in. – Juan Oct 07 '19 at 12:05
  • Hi Juan, Thanks! – user288609 Oct 07 '19 at 14:36