Error in MeasureRadialDistribution



I have problems with the MeasureRadialDistribution module. I have changed the c to a capitalized C and switched row/column as mentioned in another post.

step 1
CenterLabels = full(sparse(Centroids(1,:), Centroids(2,:), 1:size(Centroids, 2), size(LabelMatrixImage, 1), size(LabelMatrixImage, 2)));
step 2
CenterLabels = full(sparse(Centroids(2,:), Centroids(1,:), 1:size(Centroids, 2), size(LabelMatrixImage, 1), size(LabelMatrixImage, 2)));

Most of the times the module works fine untill I a have an object with its Centroid outside the object (eg strong bean shaped nucleus). I will get the following error:

"There was a problem running the analysis module MeasureRadialDistribution which is number 05. Error using ==> sparse
Index into matrix must be an integer."
in reference to the following line of code:
BinnedValues = full(sparse(LabelMatrixImage(Mask), BinIndexes(Mask), Image(Mask), NumObjects, BinCount));

Thanks for your help



We have confirmed that heavily non-convex objects are a problem, in which the centroid falls outside the object. It is not obvious what the best solution is in these cases, and you could alter your code to simply add NaN’s in the CPaddmeasurements calls if the centroid is outside the object. We have discussed it here and, as the Help text indicates, we think that defining the center, not as the centroid, but “as the point farthest from the boundary” (but necessarily within the object) is reasonable.

I’ll report the fix when we get it. Thanks for reporting this.



Thanks for your reply,

I have found a solution by using the ExpandOrShrink module. I shrink the object to one pixel and use these new objects as center for the original objects in the MeasureRadialDistribution module. This is however quite time consuming for large images with large objects. The solution you propose is probably much faster and if you have implemented this I would love to have this.



Hi Coen,

Your ExpandOrShrink solution is a decent built-in solution, however in the last couple of hours we just made one which should be faster – as well as actually match what our Help text already says! Attached is our most updated MeasureRadialDistribution module, which includes a couple of bug fixes, plus the new one. Basically, rather than using the centroid from Matlab’s regionprops, this will “Find the point per object farthest from the edge of the object” (within the object).

You should be able to replace your module with this one and run. We have confirmed that this works with a “C”-shaped object. Let us know if it works for you.

MeasureRadialDistribution.m (10.4 KB)


Hi David,

The new MeasureRadialDistribution works fine as long as I suppress visual output. Maybe this is a small bug. Thanks for the quick fix.



Hmm, that’s odd since nothing about the “DISPLAY RESULTS” code has changed from the 5811 Bugfix release to the version that I posted here. If you can paste the error text here, then I could help debug this display issue.



This is the error text from cellprofiler when I try to display the results of the module:

"There was a problem running the analysis module MeasureRadialDistribution which is number 05. Error using ==> CPimagesc
Too many input arguments.

MeasureRadialDistribution in D:\My Documents\MATLAB\CellProfiler_5811Bugfix\Modules\MeasureRadialDistribution.m (234)
AnalyzeImagesButton_Callback in D:\My Documents\MATLAB\CellProfiler_5811Bugfix\CellProfiler.m (4316)
gui_mainfcn in D:\My Documents\MATLAB\CellProfiler_5811Bugfix\CellProfiler.m (6073)
CellProfiler in D:\My Documents\MATLAB\CellProfiler_5811Bugfix\CellProfiler.m (55)"



Hi Coen,
I see the problem now and the display code did change (not sure why I didn’t see the difference before). The subfunction CPimagesc.m on our working copy now takes another argument, but your copy of CPimagesc.m doesn’t. If you replace the last section of MeasureRadialDistribution (below “%%% DISPLAY RESULTS %%%”) with the original 5811Bugfix code (pasted below), then the display error should disappear.


ThisModuleFigureNumber = handles.Current.(‘FigureNumberForModule’,CurrentModule]);
if any(findobj == ThisModuleFigureNumber)
%%% Activates the appropriate figure window.
if handles.Current.SetBeingAnalyzed == handles.Current.StartingImageSet
%%% A subplot of the figure window is set to display the distance image.
CPimagesc(NormalizedDistance, handles);
title('Input Image, cycle # ',num2str(handles.Current.SetBeingAnalyzed)]);
%%% subplot to display distance/intensity histogram
CPimagesc(FractionAtDistance, handles);
CPimagesc(MeanPixelFraction, handles);
CPimagesc(RadialCV, handles);

Sorry for the confusion,