Find the coordinates nearest to the center coordinate of a patch in an image

3 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2020 年 6 月 11 日
編集済み: Elysi Cochin 2020 年 6 月 12 日
i have an image of size [512 512], and xy coordinates values, which have been found on the whole image. (I have attached an example xy coordinate which i'm working on)
Now i wanted to divide the image into blocks of size [128 128], and
I need to find the center most xy coordinate that falls on each patch
  2 件のコメント
darova
darova 2020 年 6 月 11 日
you can divide your matrix using mat2cell
  • I wanted to find the center xy coordinate value that falls in each patch, and crop from the center a new patch of size [100 100]
Don't understand that. Can you explain?
Elysi Cochin
Elysi Cochin 2020 年 6 月 11 日
sir i have edited the question

サインインしてコメントする。

採用された回答

darova
darova 2020 年 6 月 12 日
See this simple example
x = rand(100,1); % random data
y = rand(100,1);
[x1,y1] = meshgrid(0.05:.3:1); % mesh
D = pdist2([x y],[x1(:) y1(:)]); % combinations of distances
[~,ix] = min(D); % closest distances (indices)
plot(x,y,'.r')
hold on
plot(x1,y1,'.-b','markersize',25)
plot(x1',y1','.-b')
plot(x(ix),y(ix),'om','markersize',20)
hold off

その他の回答 (1 件)

Rob Robinson
Rob Robinson 2020 年 6 月 12 日
編集済み: Rob Robinson 2020 年 6 月 12 日
centres = cell((size(ca,1)-1),(size(ca,2)-1));
for r = 1:size(ca,1)-1
for c = 1:size(ca,2)-1
centrePoint = [(blockSizeR/2 +(blockSizeR*(r-1))) (blockSizeC/2 + (blockSizeR*(c-1)))];
distance = sqrt(sum((xy-centrePoint).^2,2));
[value, rowId] = min(distance);
centres{r,c} = xy(rowId,:);
end
end
I think this is what you meant? But this won't return any kind of error if the nearest xy point lies outside of the "patch" - something to be wary of. ( I assumed the RGB array was a matrix of values size 256x256)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by