Simple segmentation of fMRI clusters for tractography ROIs

Dear All,
This is perhaps slightly off topic but I was hoping some of the more experienced neuroimagers here could point me in the right direction. I want to segment a thresholded fMRI map to only include blobs which I know are relevent seed ROI’s for tractography.

I dont belive MRview will do this? So I was wondering if anyone knew of another image viewing/analysis package (or command line tool) which might be most effective at doing this.

In essence I just want click on a single isolated region of activation and save a new nii file that will only contain this region (all other regions will be removed). I know of packages that have complicated region growing algorithims. But I am after the simplest, quickest approach possible for a person with limited training to easily undertake.

Many thanks

Have you tried the ‘fill’ function on the MRView ROI tool? If you right-click, it will erase the blob, at least on that slice. Not a full 3D blob removal, but might be quick enough for you purposes…?

Alternatively, you can try:

mrthreshold activation.nii - -abs <threshold> | maskfilter - connect blobs.nii

That will threshold your activation map at some value <threshold>, then split the resulting ‘blobs’ spatially, labelling each with a unique integer. Once you’ve used the mrview cursor to figure out which labels you want, you can turn them into binary mask ROIs using e.g.:

mrcalc blobs.nii <label> -eq blob_<label>.nii

(Sets all voxels where the value in image blobs.nii is equal to integer value <label> to true; all other voxels to false)


This is fantastic. Both appear to work. I like the command line version, although the ouptut file blobs.nii appears to not include the largest blob in the data set? I see there is a -largest option for maskfilter but for some cases the blob I wish to segment out might not be the largest?

Is there a way to get the maskfilter output to include all blobs including the largest?

Hi Jonathan,
The connected components filter will also output the largest cluster even without the -largest option. However, because the clusters are labelled according to size (with the largest cluster assigned to 1) it may not be easy to see straight away when loading in mrview because of the min-max intensity windowing. Especially if you have lots of clusters.

I’m sure you know this already, but in case you don’t, you can use the right mouse button to change the intensity windowing.

If you are definitely not getting the largest cluster, then this is not the desired behaviour and I’d be happy to take a look at your image.


It also might be easier for you to visualise/pick your cluster by viewing the thresholded map, then extract out a single cluster/blob using a voxel position:

maskfilter thresholded_activation.nii connect blobs.nii; mrcalc blobs.nii $(mrstats blobs.nii -voxel 50,50,50 -output mean) -eq blob.nii

where 50,50,50 is the x,y,z index of a voxel within the cluster of interest.

1 Like

Dave you were actually completely correct and when I load Blobs.nii in as the image you can see that the largest Blob has the index of 1 (interestingly the value actually tends to be 0.99999999). However no matter how I window the Blobs image when it is an overlay I can never make it visible. See below two images. The first is with the blobs as the main image the second is with the blobs as the overlay image. Not the image intensities at the cross hair for the blob I am trying to extract. Am I missing something with the overlay windowing?

Hmm, that is odd. The large cluster has a value of 1 and and should definitely show up in the range of 0.5-1.5 using the overlay tool.

What version of mrview are you using? You can get this by clicking “Info->About”. If you are willing to share the images I’d be happy to check on my end too.

On a related note, one discrepancy between viewing the image in the main window vs an overlay is that the windowing in the main window it is based on the min and max within the shown slice. However, in overlay mode if you click the colorbar icon and then ‘reset’ it will window based on the min and max over the whole image. This is not the issue here but just something to be aware of.

I am using version 0.3.14-646-g9bf930b4.

The commands you suggested for identifying the blob via voxel location work really well too. This is brilliant as it is exactly what I am after and I have now incorporated it into my pipeline. This actually means I don’t need to see the blob with intensity = 1 now anyway. I tried uploading the file anyway as it would be interesting to discover what the issue is, however, I cant seem to upload .nii files, even if I try to send to you direct? What is the best way to send you the file?

Just to hijack with another, probably really basic question. When I use mrview on my mac the two finger scroll (both on a track pad and using a magic mouse) doesn’t scroll through the slices as does the wheel on a standard mouse (plugged into the same machine). Is two finger scrolling not implemented? Thanks for all your help.

Yes, this is an issue that’s been on the todo list for a while, so I’ve decided to do something about it. Take a look at the changes in the macosx_fixes branch on GitHub, see if that fixes things for you.

Brief instructions:

$ git fetch
$ git checkout macosx_fixes
$ ./build

Once you’re done testing, and want to revert back to the master branch:

$ git checkout master
$ ./build

Hopefully, we’ll merge these changes to master fairly quickly anyway - I just want to get a bit of feedback as to whether these changes actually work as expected for everyone before doing so…

All MacBook users: please feel free to try the above and report back here - the more testing the better!

Users with Windows laptops: if you have a touchpad with multi-touch support, these features should also theoretically work there. It would be great to get some feedback from you too!

Scrolling works fine on my macbook air but pinch and zoom is way too fast. The tiniest zoom causes about 20 changes of FOV with each e->scaleFactor() of the order of 20 to 30% which makes the FOV jump several orders of magnitude.

Darn… OK, let’s take the touchpad conversation over to the relevant GitHub pull request

Hi, quick question that I can’t seem to figure out - where is it that you see this unique integer? I have followed these steps and have tried loading in the blobs.nii to both the overlay and ROI options but but I don’t see anything suggestive of the unique overlay. Maybe I’m loading the image in wrong somehow? Thanks in advance!

If you load an image as a standard image in mrview, then the image value underneath the cursor is displayed in the yellow text in the bottom-left corner. If you load some other image, then open your label image of interest within the Overlay tool, then the value underneath the cursor is still printed in the same place on the screen; it’s just stated that it’s the value of the overlay image, not the main image.

Sometimes it will show the value as e.g. ‘0.999999’ rather than ‘1’: This is because the image is being displayed using interpolation, and the value underneath the cursor is correspondingly being determined using interpolation, and can therefore have small floating-point errors. Turning off image interpolation (of the main image or in the Overlay tool respectively) changes this behaviour.

If you can’t see anything in the image, I would first run mrstats to make sure the image isn’t in fact empty (mrstats blobs.nii -mask blobs.nii will give you the added advantage of seeing how many non-zero voxels are in the image). Then, load some other image as the main mrview image, and open the label image using the overlay tool: this will automatically set the intensity windowing of the label image according to the entire image volume. It’s then simply a matter of scrolling up and down until you spot something…

If you still don’t see anything, check that in the Overlay tool:

  • The button with the big eye with the cross through it is not pushed down (this hides all overlay images)

  • The box next to the image file name should be checked

  • The intensity scaling should be reasonable (should go from 0 to the maximum label in the image)

  • The threshold controls should be un-checked (i.e. no thresholds applied, which could otherwise hide your blobs)

  • The opacity slider should be towards the right


I can see it! Thank you. I was overlaying the blobs.nii onto the anat file and so the value would change wherever I put the cursor even within one blob. I guess it must have been showing the value from the anat file. The first time I loaded the blobs.nii it just looked empty so I ran the stats as you suggested and it was not so it just took some looking through the image to find the blob. But loading as the standard image I know see the values corresponding to the unique integer.

Thanks again! I really appreciate that :slight_smile: