<div dir="ltr"><div><div>Sorry, I can't provide an example right now as I am super busy, but the magic is that you do not need to iterate at all!<br></div>You will get an array of one value (the average) per ROI (the ROIs are numbered 1 to n in the mask file).<br></div><br>I just greped in the examples folder of nilearn and there are two scripts that you may want to check:<br><br><br>./04_manipulating_images/plot_roi_extraction.py:# We extract data from ROIs using nilearn's NiftiLabelsMasker<br><br>./03_connectivity/plot_signal_extraction.py:masker = NiftiLabelsMasker(labels_img=atlas_filename, standardize=True,<br><br><div><br><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 14, 2018 at 11:25 AM, Gabriel Reynés <span dir="ltr"><<a href="mailto:greynell@gmail.com" target="_blank">greynell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Christophe<span> </span></span>
,<div><br></div><div><br></div><div>Thanks for your answer! I spent many hours triyng to figure the behaviour of NiftiLabelsMasker</div><div>I do not understand how to iterate over each mask ROI.</div><div><br></div><div>How one can iterate over each label of a masker?</div><div><br></div><div>`# Obtain AAL Atlas</div><div><div>aal = datasets.fetch_atlas_aal('<wbr>SPM12')</div><div>aal_labels = aal.labels</div><div><br></div><div># Obtain mask</div><div>masker = input_data.NiftiLabelsMasker(<wbr>aal.maps)<br></div><div><br></div><div># Input image to compute the mean value for each</div><div>patient_img = image.load_img(path_nii)<br></div><div>
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">patient_img<span> </span></span>
=
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">patient_img</span>.get_data()<br></div><div><br></div><div># Fit the mask to the image</div><div>masker_fit(patient_img)</div><div>mask_img = masker_fit.mask_img_</div><div><br></div><div>Thanks in advance,</div><div><br></div><div><br></div><div>Gabriel</div><div><br></div><div><br></div><div><br></div><div></div></div></div>
<br>______________________________<wbr>_________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--<br>Christophe Pallier <<a href="mailto:christophe@pallier.org" target="_blank">christophe@pallier.org</a>><br>INSERM-CEA Cognitive Neuroimaging Lab, Neurospin, bat 145,<br>91191 Gif-sur-Yvette Cedex, France<br>Tel: 00 33 1 69 08 79 34<br>Personal web site: <a href="http://www.pallier.org" target="_blank">http://www.pallier.org</a><br>Lab web site: <a href="http://www.unicog.org" target="_blank">http://www.unicog.org</a><br></div>
</div>