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!