フィルターのクリア

Problem with rotating an image

2 ビュー (過去 30 日間)
Ely Raz
Ely Raz 2023 年 11 月 21 日
コメント済み: Image Analyst 2023 年 11 月 22 日
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

回答 (1 件)

Image Analyst
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 件のコメント
Ely Raz
Ely Raz 2023 年 11 月 22 日
Hi,
Thanks.
I was applying your comments and also fixed the Orientation issue. I think the structure array issue is repetitive in all the script as I get this error with this line
line(app.objectRotateEditorAxes, [stat.MaxFeretCoordinates(1),stat.MaxFeretCoordinates(2)],[stat.MaxFeretCoordinates(3),stat.MaxFeretCoordinates(4)],'Color','blue','LineWidth',2);
Error using GMRotateVer11/ManualrotateButtonPushed
Intermediate dot '.' indexing produced a comma-separated list with 5 values, but it must produce a single value
when followed by subsequent indexing operations.
Any idea how can I solve this error as I presume it will occur also with MinFeretCoordinates?
Thanks a lot again and I highly appriciate it.
Code:
function ManualrotateButtonPushed(app, event)
[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;
xy = vertcat(stat.Centroid); % Get all N blobs centroids into an N by 2 array with x=column1 and y=column2.
xCentre = xy(:, 1);
yCentre = xy(:, 2);
oriTemp = vertcat(stat.Orientation);
ori = oriTemp(1, 1);
% cosOrient = cosd(stat.Orientation);
% sinOrient = sind(stat.Orientation);
cosOrient = cosd(ori);
sinOrient = sind(ori);
xcoords = xCentre + hlen * [cosOrient -cosOrient];
ycoords = yCentre + hlen * [-sinOrient sinOrient];
line(app.objectRotateEditorAxes, xcoords, ycoords, 'Color','magenta','LineWidth',2);
line(app.objectRotateEditorAxes, [stat.MaxFeretCoordinates(1),stat.MaxFeretCoordinates(2)],[stat.MaxFeretCoordinates(3),stat.MaxFeretCoordinates(4)],'Color','blue','LineWidth',2);
line(app.objectRotateEditorAxes, [stat.MinFeretCoordinates(1),stat.MinFeretCoordinates(2)],[stat.MinFeretCoordinates(3),stat.MinFeretCoordinates(4)],'Color','green','LineWidth',2);
app.orientationAngleLabel.Text = strcat("Orientation angle: ", num2str(stat.Orientation));
app.minFeretangleLabel.Text = strcat("Min. Feret angle: ", num2str(stat.MinFeretAngle));
app.maxFeretangleLabel.Text = strcat("Max. Feret angle: ", num2str(stat.MaxFeretAngle));
app.Iworking = app.IManualAngleRotImg;
app.outline2save = [app.yBoundary app.xBoundary]
%imshow(app.Iworking);
end
Image Analyst
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 ExchangeTime Series Objects についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by