필터 지우기
필터 지우기

Creating a Grid for cooridnates

조회 수: 4 (최근 30일)
Jason
Jason 2023년 10월 13일
댓글: Jason 2023년 10월 16일
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

채택된 답변

Matt J
Matt J 2023년 10월 15일
편집: Matt J 2023년 10월 15일
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
Matt J
Matt J 2023년 10월 15일
편집: Matt J 2023년 10월 15일
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.
Jason
Jason 2023년 10월 16일
Thanks Matt, it all works beautifully!
Spurious spots removed!
Can even get the angle

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2023년 10월 13일
편집: Matt J 2023년 10월 13일
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
Matt J
Matt J 2023년 10월 14일
Problem solved, then? If so, please Accept-click the answer.
Image Analyst
Image Analyst 2023년 10월 14일
I think you could also use kmeans() to count the number of rows and column.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by