If anyone is looking for the solution you can do this if you have one centroid in the image
If you want to get the grid row and column numbers, you should plot the grid with predefined grid row and column width:
rowWidth = 52; % Grid row width in pixels
colWidth = 53; % Grid column width in pixels
[rows, columns, ~] = size(Image);
for row = 1 : rowWidth : rows
line([1, columns], [row, row], 'Color', 'r');
end
for col = 1 : colWidth : columns
line([col, col], [1, rows], 'Color', 'r');
end
To get the the grid row and column numbers (assuming you have only one centroid):
% Get the row and column of the centroid (in grid units)
centroidGridCol = ceil(stat(1).Centroid(1) / colWidth);
centroidGridRow = ceil(stat(1).Centroid(2) / rowWidth);