Neuroimaging clustering FMRI

Hi,
please i have a dataset with nifti image of dim (182,190,182) , i want to do a clustering, so i used Kmeans but it is very slow , so i find a method which is very fast which is ReNA method in Nilearn , i applied a mask with NiftIMasker and when i apply the ReNa method i have a problem

 File "<ipython-input-39-b94ed8840ef7>", line 1, in <module>
 b= rena.fit_transform(masked_data)

File "C:\Users\moham\Anaconda3\lib\site-packages\sklearn\base.py", line 553, in 
fit_transform
return self.fit(X, **fit_params).transform(X)
File "C:\Users\moham\Anaconda3\lib\site- 
packages\nilearn\regions\rena_clustering.py", line 483, in fit estimator=self)

File "C:\Users\moham\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 
550, in check_array context))

ValueError: Found array with 1 sample(s) (shape=(1, 1534813)) while a minimum of 
2 is required by ReNA.

My Code :
from nilearn.masking import compute_epi_mask
from nilearn.masking import apply_mask

img= read_nifti(“CT01003BOIJE.nii.gz”)
img.shape # (182,218,182)

mask_img = compute_epi_mask(img)
masked_data = apply_mask(img, mask_img)
rena = ReNA(mask_img, n_clusters=20, scaling=False,
n_iter=10,threshold=1e-07, memory=None,
memory_level=1, verbose=0)
b= rena.fit_transform(masked_data)

Hi,

In order to fit ReNA, the number of images required is more than 1. That is what the error message says.

ReNA is recommended if one needs to more than 2000 clusters.
See https://github.com/nilearn/nilearn/issues/2134

The computation of masking steps can be overcome by using ReNA from the Parcellations object.
Have a look at this example which shows how to compute parcels using Parcellations object.
https://nilearn.github.io/auto_examples/03_connectivity/plot_data_driven_parcellations.html#sphx-glr-auto-examples-03-connectivity-plot-data-driven-parcellations-py

Thank you for your response.
But if i have 267 nifti images of shape (182,190,182)
how i can fit ReNA with all this images : which method will be used to assemble all this image to be fited by ReNA ?

If you have 267 such images then you could directly provide them as list of images to ReNA.

imgs = [“CT01001BOIJE.nii.gz”, “CT01002BOIJE.nii.gz”, “CT01003BOIJE.nii.gz”, …]

For example, look at this demo
https://nilearn.github.io/manipulating_images/input_output.html#inputing-data-file-names-or-image-objects

Thank you very much @KamalakerD

MANAGED BY INCF