PROPERTY must be a string error using regionprops

조회 수: 4 (최근 30일)
Aaron Smith
Aaron Smith 2017년 8월 9일
댓글: Aaron Smith 2017년 8월 10일
I am using regionprops to calculate the mean intensity inside three regions of interest on a a number of matrices.
while again
thisRegion = roipoly;
% Add this in to the main one
finalImage = finalImage | thisRegion;
promptMessage = sprintf('Do you want to add another region?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(buttonText, 'No')
again = false;
end
labeledImage = logical(finalImage);
end
mask = labeledImage;
Y = handles.finishCell;
for i = 1 : length(Y)
thisImage = Y(i); % Extract matrix from cell array of matrices.
%Get allIGLs for that image.
props = regionprops(mask, thisImage, 'Area', 'MeanIntensity');
allAreas = [props.Area];
allMeans = [props.MeanIntensity];
allIGLs = allAreas .* allMeans;
caIGLs{i} = allIGLs; % Store IGLs for this image into a cell array.
end
The last time I tried this code it did not generate an error and then I tried using the GUI again, having run it again and a very long series of errors arose. Matlab also stopped responding to some commands. I restarted Matlab and ran the code again. This time this error occurred:
Error using regionprops>getPropsFromInput (line 1179)
PROPERTY must be a string.
Error in regionprops>ParseInputs (line 1133)
reqStats = getPropsFromInput(startIdxForProp, ...
Error in regionprops (line 154)
[I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
Error in hopefully_the_last_window>pushbutton3_Callback (line 196)
props = regionprops(labeledImage, thisImage, 'Area', 'MeanIntensity');
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in hopefully_the_last_window (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)hopefully_the_last_window('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I am not sure if this is due to the inputs (the logical mask and the cell array) or something else. In the code itself, the variable caIGLs has an attention underline stating that the variable appears to change size on every loop iteration. Consider preallocating for speed.
Each of the matrices in the cell array are the same size so I'm not sure how the final variable caIGLs can change each time.

채택된 답변

Image Analyst
Image Analyst 2017년 8월 9일
You're getting a cell. You need to get the CONTENTS of the cell, which is presumably your image, so use braces not parentheses:
thisImage = Y{i};
See the FAQ for a good intuitive discussion of what a cell and cell array are: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
  댓글 수: 2
Aaron Smith
Aaron Smith 2017년 8월 9일
Thanks Image Analyst. I changed this before, I seem to recall having changed it from {} to () to make it work. Perhaps I was mixed up and I forgot to save it after I changed it last
Aaron Smith
Aaron Smith 2017년 8월 10일
Does this code sum all of the cells together? When I used xlswrite to create an excel spreadsheet of the data it contains only two columns (which would be the two selected regions of interest) with extremely large number. This is what led me to believe that allAreas is the sum of the area of the ROI for all the cells and that allMeann is the sum of the average of intensity for each cell. When I save caIGLs in a folder as a .mat file, it does not open in matlab: Unable to read file testData.mat: No such file or directory.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by