Problem with rotating an image
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Image Analyst
el 21 de Nov. de 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 comentarios
Image Analyst
el 22 de Nov. de 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.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!