Creating a Grid for cooridnates
Show older comments
Hello, I have an image where i have foudn the location of the spot centroid. I have the liist of all the coordimates.
What I want to do is create a set of vertical lines that is an average of the spots x positon, so in this case 4 vertical lines of which I have shown 1 below). and then do it for the horizontal lines.

In reality my images change in size and I can have upto 50x50 spots.
these are the actual coordiantes (x,y)
3.9988 76.5058
5.4914 203.4980
7.3364 330.4643
130.3843 77.1741
132.5535 204.2574
134.5383 331.2441
257.6364 77.8253
259.6390 205.0028
261.5130 331.9971
385.1154 78.8457
386.9360 205.8598
388.7871 332.6533
(Or Broken in to single column vectors)
x =
3.9988
5.4914
7.3364
130.3843
132.5535
134.5383
257.6364
259.6390
261.5130
385.1154
386.9360
388.7871
y =
76.5058
203.4980
330.4643
77.1741
204.2574
331.2441
77.8253
205.0028
331.9971
78.8457
205.8598
332.6533
Accepted Answer
More Answers (1)
x =[3.9988
5.4914
7.3364
130.3843
132.5535
134.5383
257.6364
259.6390
261.5130
385.1154
386.9360
388.7871];
y =[76.5058
203.4980
330.4643
77.1741
204.2574
331.2441
77.8253
205.0028
331.9971
78.8457
205.8598
332.6533];
scatter(x,y)
[~,~,~,Gx,Gy]=histcounts2(x,y,[4,3]);
xl=splitapply(@mean,x,Gx);
yl=splitapply(@mean,y,Gy);
xline(xl,'r--'); yline(yl,'r--')
7 Comments
Jason
on 13 Oct 2023
It assumes that, but there are a number of different options for specifying the binning which you will see in the doc for histcounts2. The one that applies will depend on what info you have. For example, maybe you know that the (x,y) are always separated by at least 50.
Here's a morphological way you can find the number of rows and columns of points from the original binarized image:
load Image
coarsify=@(I) imdilate(cummax(I,2),ones(5,1));
R=coarsify(Image);
C=coarsify(Image')';
rows=bwconncomp(R).NumObjects
columns=bwconncomp(C).NumObjects
immontage({Image,R,C},'Bor',[15,15],'Size',[1,3],'Back','r');
Jason
on 14 Oct 2023
Jason
on 14 Oct 2023
Matt J
on 14 Oct 2023
Problem solved, then? If so, please Accept-click the answer.
Image Analyst
on 14 Oct 2023
I think you could also use kmeans() to count the number of rows and column.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






