Index in position 1 is invalid.
4 次查看(过去 30 天)
显示 更早的评论
Good day,
I have made the following Script to sotre the coordinates of centroid of laser beam from images
directory = 'C:\Users\anask\Desktop\test\';
Coordination = zeros(7,3);
files = dir([directory '/*.jpg']);
[~,index] = sortrows({files.date}.'); files = files(index); clear index;
for x = 1: numel(files)
A= imread([directory '/' files(x).name]);
%Convert the image ino binary image
Ibw = im2bw(A);
%Fill image regions and holes
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
%finding the centroid
stat = regionprops(Ibw,'Area','Centroid');
%Creating new array that have Area, X-coordinate, Y-coordinate
area = cat(1,stat.Area);
Coor = cat(1,stat.Centroid);
%Combaining the results in one Array
Array = cat(2,area,Coor);
%Adding header
%header = {'Area','x','y'};
%Array = [header; num2cell(Array)];
%Finding the maximum value
maximum = max(max(Array(:,1)));
[x,y]=find(Array==maximum);
%Apped the line of the maximum value in a new array
if ~isempty(Coordination)
Coordination(i,1:2) = Array(x,2:3);
end
clear stat
clc
end
And I am keep getting the following error
----------------------------------
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Test (line 34)
Coordination(i,1:2) = Array(x,2:3);
------------------------------------
Can someone help me please to fix this issue, I want to store the coordinates in the coordinate array. The coordinate are derived from the row of the maximum area in 'Array' array.
Many thanks in advanced
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!