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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by