<div dir="ltr">Hi Matteo!<div><br></div><div>The function you're looking for is as simple as convolution [1] with a typical structuring element [2] (we have square, circle and many more). I suppose, this can also be called as 'mean filter':</div><div><br></div><div>Here is an example:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">import numpy as np<br>import scipy.ndimage as ndi<br>from skimage.morphology import square<br><br>img = np.random.uniform(size=(5, 5))<br>img = (img > 0.5).astype(np.float)<br>sem = square(3)/3**2   # Don't forget to normalize<br>out = ndi.convolve(img, sem, mode='wrap')<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">print(img)<br>print(sem)<br>print(out)</blockquote><div><br></div><div>Results to: </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">[[ 1.  0.  0.  1.  0.]<br> [ 1.  0.  0.  0.  0.]<br> [ 0.  0.  1.  1.  0.]<br> [ 0.  0.  0.  0.  1.]<br> [ 1.  0.  1.  0.  0.]]<br>[[ 0.11111111  0.11111111  0.11111111]<br> [ 0.11111111  0.11111111  0.11111111]<br> [ 0.11111111  0.11111111  0.11111111]]<br>[[ 0.33333333  0.44444444  0.22222222  0.22222222  0.44444444]<br> [ 0.22222222  0.33333333  0.33333333  0.33333333  0.44444444]<br> [ 0.22222222  0.22222222  0.22222222  0.33333333  0.33333333]<br> [ 0.22222222  0.33333333  0.33333333  0.44444444  0.33333333]<br> [ 0.33333333  0.33333333  0.22222222  0.33333333  0.44444444]]</blockquote><div><br></div><div>Cheers,</div><div>Egor</div><div><br></div><div>[1] <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.convolve.html#scipy.ndimage.convolve">http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.convolve.html#scipy.ndimage.convolve</a> </div><div>[2] <a href="http://scikit-image.org/docs/dev/api/skimage.morphology.html#module-skimage.morphology">http://scikit-image.org/docs/dev/api/skimage.morphology.html#module-skimage.morphology</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-05-26 18:11 GMT+03:00 Matteo <span dir="ltr"><<a href="mailto:matteo.niccoli@gmail.com" target="_blank">matteo.niccoli@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Is there a function in scikit-image to calculate the the local density of 1s in a binary image?<div><br></div><div>By local density of 1s I mean:</div><div>1) count the number of pixels that have value of 1 in a running/sliding window (preferrably circular but square would work too)</div><div>2) divide by the total number of pixels in the running window</div><div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>Matteo</div></font></span></div><span class="HOEnZb"><font color="#888888">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "scikit-image" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:scikit-image+unsubscribe@googlegroups.com" target="_blank">scikit-image+unsubscribe@googlegroups.com</a>.<br>
To post to this group, send email to <a href="mailto:scikit-image@googlegroups.com" target="_blank">scikit-image@googlegroups.com</a>.<br>
To view this discussion on the web, visit <a href="https://groups.google.com/d/msgid/scikit-image/1b36234e-79ed-4eec-9c4a-ea1b659069f3%40googlegroups.com?utm_medium=email&utm_source=footer" target="_blank">https://groups.google.com/d/msgid/scikit-image/1b36234e-79ed-4eec-9c4a-ea1b659069f3%40googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/optout</a>.<br>
</font></span></blockquote></div><br></div>