Creating a Grid for cooridnates
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Matt J
am 15 Okt. 2023
Bearbeitet: Matt J
am 15 Okt. 2023
and I also do pick up a few spurious spots that are'nt part of the grid
If outliers are present, I would use the approach below, which requries the download of this FEX contribution,
I don't really know the distribution of your outliers, so that may affect choices of certain parameters, as noted below in the code.
load Image_outliers
C=vertcat(regionprops(Image,'Centroid').Centroid);
x=C(:,1);
y=C(:,2);
D=pdist2([x,y],[x,y],'city','Smallest',2);
D(1,:)=[];
d=median(D(:));
Xedges=binEdges(x,d);
Yedges=binEdges(y,d);
[~,~,~,Gx,Gy]=histcounts2(x,y,Xedges,Yedges);
xl=splitapply(@median,x,Gx);
yl=splitapply(@median,y,Gy);
imshow(Image,[]);
xline(xl,'y--'); yline(yl,'y--')
function edges=binEdges(z,d)
Z=-d/2:round(max(z)+d/2);
T=sum(abs(Z-z(:))<=d/5,1);
thresh=0.5*max(T); %depends on outlier rate
[start,stop]=groupLims(groupTrue(T<=thresh),1);
edges=(Z(start)+Z(stop))/2;
end
3 Kommentare
Matt J
am 15 Okt. 2023
Bearbeitet: Matt J
am 15 Okt. 2023
So if I wanted to have a seperate median for x and y distances, is this possible?
If you know a fairly tight upper bound on the distance of the points from their grid lines (e.g., 10 pixels) then you can do as below,
dx=dmedian(x);
dy=dmedian(y);
function d=dmedian(u)
D=abs(u(:)-u(:)');
D(D<10)=inf;
d=median(min(D));
end
In the example below, Im trying to see if there is always a pattern to how D is calculated i.e. is it always top left and next point below?
No, the second row of D is just the distance from each (x,y) to its nearest neighbor, whichever that happens to be.
Weitere Antworten (1)
Matt J
am 13 Okt. 2023
Bearbeitet: Matt J
am 13 Okt. 2023
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 Kommentare
Image Analyst
am 14 Okt. 2023
I think you could also use kmeans() to count the number of rows and column.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!