Problem with rotating an image
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2023-11-21
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 个评论
Image Analyst
2023-11-22
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!