How I get this all values of regionprops and show in diferent edit texts in my GUI?

3 vues (au cours des 30 derniers jours)
stats = regionprops('table',CloseBW,'Area',...
'BoundingBox',...
'Centroid',...
'EquivDiameter',...
'MajorAxisLength',...
'MinorAxisLength',...
'Perimeter')

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Nov 2017
set( handles.Areas, cellstr( str2num(stats.Area) ) )
This would require that handles.Areas is a uicontrol style text or style edit whose Max property has been set to 2 or more so that it will expect multiline inputs.
Have you considered outputting to a uitable instead of to individual edit fields? You could use table2cell() to make it easier.
  3 commentaires
Image Analyst
Image Analyst le 16 Nov 2017
Huh?
set( handles.Areas, cellstr( str2num(stats.Area) ) )
doesn't work. For one thing, stats.Area is already a number if there's just a single blob so it can't be passed into str2num. And if there are several structures (blobs), then it gets even worse.
My code below works beautifully, even for multiple blobs.
Walter Roberson
Walter Roberson le 17 Nov 2017
set( handles.Areas, cellstr( num2str([stats.Area]) ) )

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 16 Nov 2017
You could try sprintf(). For example
allAreas = [stats.Area];
handles.text1.String = sprintf('%d, ', allAreas);

Marlon Damaceno
Marlon Damaceno le 17 Nov 2017
Hello guys!
I got it in a different, simpler way, easier than I thought.
%%***AREA*** %%
Area = cat(1, 'stats.Area');
RpropsArea = cat(1, stats.Area)
set(handles.AreaInput, 'String', num2str(RpropsArea))
%%***BOUNDINGBOXINPUT*** %%
Bounding = cat(1, 'stats.BoundingBox');
RpropsBoundingBox = cat(1, stats.BoundingBox)
set(handles.BoundingBoxInput, 'String', num2str(RpropsBoundingBox))
%%***CENTROID*** %%
Centroid = cat(1, 'stats.Centroid');
RpropsCentroid = cat(1, stats.Centroid)
set(handles.CentroidInput, 'String', num2str(Centroid))
%%***EQUIVDIAMETER*** %%
EquivDiameter = cat(1, 'stats.EquivDiameter');
RpropsEquivDiameter = cat(1, stats.EquivDiameter)
set(handles.EquivDiameterInput, 'String', num2str(RpropsEquivDiameter))
%%***MAJORAXISLENGHT*** %%
MajorAxisLenght = cat(1, 'stats.MajorAxisLength');
RpropsMajorAxisLenght = cat(1, stats.MajorAxisLength)
set(handles.MajorAxisLenghtInput, 'String', num2str(MajorAxisLenght))
%%***MINORAXISLENGHT*** %%
MinorAxisLenght = cat(1, 'stats.MinorAxisLength');
RpropsMinorAxisLenght = cat(1, stats.MinorAxisLength)
set(handles.MinorAxisLenghtInput, 'String', num2str(MinorAxisLenght))
%%***PERIMETER*** %%
Perimeter = cat(1, 'stats.Perimeter');
RpropsPerimeter = cat(1, stats.Perimeter)
set(handles.PerimeterInput, 'String', num2str(RpropsPerimeter))

Community Treasure Hunt

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

Start Hunting!

Translated by