Problem with rotating an image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have a code within app designer which is aim in rotating an object but I get sometimes this error:
c
=
1.0e+03 *
1.0595 1.0271
Intermediate dot '.' indexing produced a comma-separated list with 2 values, but it must produce a single value
when followed by subsequent indexing operations.
Error in RotateV/ManualrotateButtonPushed (line 765)
xCentre = stat.Centroid(1);
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Related documentation
Error while evaluating Button PrivateButtonPushedFcn.
The relevant code is:
[B,L] = bwboundaries(app.Iworking,'noholes');
k=1;
stat = regionprops(L,"Centroid","MajorAxisLength","Orientation","MinFeretProperties","MaxFeretProperties");
b = B{k};
c = stat(k).Centroid;
app.yBoundary = b(:,2);
app.xBoundary = b(:,1);
cy = c(:,2);
cx = c(:,1);
app.IManualAngleRotImg = imrotate(app.Iworking, app.rotateEditField.Value);
[B,L] = bwboundaries(app.IManualAngleRotImg,'noholes');
k=1;
stat = regionprops(L,"Centroid","MajorAxisLength","Orientation","MinFeretProperties","MaxFeretProperties");
b = B{k};
c = stat(k).Centroid
app.yBoundary = b(:,2);
app.xBoundary = b(:,1);
cy = c(:,2);
cx = c(:,1);
imshow(app.IManualAngleRotImg,'Parent', app.objectRotateEditorAxes)
hold(app.objectEditorAxes,'on');
plot(app.objectRotateEditorAxes, app.yBoundary, app.xBoundary, 'red', 'linewidth', 2);
hlen = stat.MajorAxisLength;
xCentre = stat.Centroid(1);
yCentre = stat.Centroid(2);
Any idea how can I solve it? is it related to the "1.0e+03 *" outcome, Can someone help?
Thanks a lot
0 Kommentare
Antworten (1)
Image Analyst
am 21 Nov. 2023
stat is a structure array, not a single structure.
Try this
xy = vertcat(stat.Centroid); % Get all N blobs centroids into an N by 2 array with x=column1 and y=column2.
cx = xy(:, 1); % Or xCenter = xy(:, 1);
cy = xy(:, 2); % Or yCenter = xy(:, 2);
2 Kommentare
Image Analyst
am 22 Nov. 2023
Again, stat is a structure ARRAY, not a single structure so you're going to have to give an index. If you want to do it like you're doing, stat would have to be a table. To do that add the 'table' option to regionprops.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!