imref2d error: Array indices must be positive integers or logical values.

1 回表示 (過去 30 日間)
Zi Qing Chua
Zi Qing Chua 2022 年 9 月 4 日
回答済み: Matt J 2022 年 9 月 4 日
Hi everyone,
I'm trying to calculate the circles from my figure, but the code shows error.
Command window shows:
Array indices must be positive integers or logical values.
Error in trial0621 (line 12)
RI = imref2d(size(subtract),xWorldLimits,yWorldLimits);
when I run the code. Does somebody know how to fix the error? Thank you very much for the help.
Here's my code:
clc
xWorldLimits = [-960 960];
yWorldLimits = [-600 600];
blank1 = imread('C:\Users\zz\Desktop\sample images for matlab\backg.bmp');
data = imread('C:\Users\zz\Desktop\sample images for matlab\test1.bmp');
subtract = data-blank1;
enhance = imadjust(subtract,[0.001 0.03]);
gray = rgb2gray(enhance);
BW = imbinarize(gray,'global');
SE = strel("disk",3);
BW2 = imopen(BW,SE);
RI = imref2d(size(subtract),xWorldLimits,yWorldLimits);
imshow(BW2,RI);
[brightcenters,brightradii,brightmetric] = imfindcircles(BW2,[5 50],'ObjectPolarity','bright','sensitivity',0.85);
h = viscircles(brightcenters,brightradii);
hold on
grid on
plot(brightcenters(:,1),brightcenters(:,2),'+','LineWidth',1.5)
count = height(brightradii)
size = mean(brightradii)
Mx = mean(brightcenters(:,1))
stdevx = std(brightcenters(:,1))
My = mean(brightcenters(:,2))
stdevy = std(brightcenters(:,2))

回答 (1 件)

Matt J
Matt J 2022 年 9 月 4 日
You have hidden the size() command by creating avariable called "size".
size = mean(brightradii)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by