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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by