from skimage import graph, data,segmentation
from matplotlib import pyplot as plt
import numpy as np
#creating a segmented image
im = data.immunohistochemistry()
seg = segmentation.felzenszwalb(im, scale=200, sigma=0.7, min_size=50)
BW = segmentation.find_boundaries(seg)
im[BW==1]=0
plt.imshow(im)
plt.show()
from skimage.measure import regionprops
Props = regionprops(seg,['Area'])
#here is the code for creating the regionprops image
labels = np.unique(seg) #a vector of label vals
PropIM = np.zeros_like(seg) # allocated blank array
for label in labels:
propval=Props[label-1]['Area']
PropIM[seg==label]=propval
#for visualising with segment boundaries
PropIM[BW==1]=0
plt.imshow(PropIM, vmin=PropIM.min(), vmax=PropIM.max())
plt.colorbar()
plt.show()
Maybe, there is a way to elegantly integrate this into the RegionProperty class?
Could you share your current implementation, so we can decide for a good strategy?
> On Mar 2, 2015, at 6:02 PM, ciara...@googlemail.com wrote:
>
> Hi Johannes,
>
> Yeah of course. Would it be best placed in module color?
>
> Ciaran
>
> On Monday, March 2, 2015 at 5:26:12 PM UTC, Johannes Schönberger wrote:
> That sounds great. Would you be willing to work on integrating this into skimage?
>
> Thanks.
>
> > On Feb 26, 2015, at 11:51 AM, ciara...@googlemail.com wrote:
> >
> > Hi
> > Adding to my own post but hey....
> >
> > I have since written my own code which allows visualising of region properties (eg area, eccentricity etc) via colormap, if anyone is interested let me know!
> >
> > Ciaran
> >
> > On Sunday, February 1, 2015 at 11:45:44 PM UTC, ciara...@googlemail.com wrote:
> > Hello everyone,
> >
> > I have recently been attempting to modify some existing skimage code to display regionprops for a labeled image (e.g. area or eccentricity)
> >
> > I initially tried to translate a vectorized bit of old matlab code I had, but gave up on that and decided to alter the existing label2rgb skimage function
> >
> > I am attempting to change each label value to it's area property value similar to the label2rgb "avg" function.
> >
> > so I have:
> > labels = a labeled image
> >
> > out = np.zeros_like(labels) #a blank array
> > labels2 = np.unique(labels) #a vector of label vals
> > out = np.zeros_like(labels)
> > Props = regionprops(labels, ['Area'])
> > bg_label=0
> > bg = (labels2 == bg_label)
> > if bg.any():
> > labels2 = labels2[labels2 != bg_label]
> > out[bg] = 0
> > for label in labels2:
> > mask = (labels == label).nonzero()
> > color = Props[label].area
> > out[mask] = color
> > but the "out" props image does not correspond to the correct area values?
> > Can anyone help me with this?
> > It also throws the following error:
> > "list index out of range"
> > It would certainly be useful to have a way to view the spatial distribution of label properties in this way - perhaps in a future skimage version?
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "scikit-image" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com .
> > For more options, visit https://groups.google.com/d/optout .
>
>
> --
> You received this message because you are subscribed to the Google Groups "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout .