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

1 Ansicht (letzte 30 Tage)
Zi Qing Chua
Zi Qing Chua am 4 Sep. 2022
Beantwortet: Matt J am 4 Sep. 2022
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))

Antworten (1)

Matt J
Matt J am 4 Sep. 2022
You have hidden the size() command by creating avariable called "size".
size = mean(brightradii)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by