フィルターのクリア

how to find distance of each pixel of image from center of image

6 ビュー (過去 30 日間)
Pratik Oak
Pratik Oak 2018 年 2 月 5 日
コメント済み: Jan 2019 年 4 月 8 日
I am interested to find the distance between each pixel of an image with respect to center of image. It is independent of gray level.

採用された回答

Jan
Jan 2018 年 2 月 5 日
編集済み: Jan 2019 年 4 月 8 日
If your image has 640 x 480 pixels, and the center is at the pixel 320 / 240:
img = rand(480, 640);
y = 1:size(img, 1);
x = 1:size(img, 2);
c = [240, 320];
D = sqrt((y.' - c(1)) .^ 2 + (x - c(2)) .^ 2); % >= R2016b
With older Matlab versions:
D = sqrt(bsxfun(@plus, (y.' - c(1)) .^ 2, (x - c(2)) .^ 2));
This is the distance measured in pixels.
  2 件のコメント
Pratik Oak
Pratik Oak 2018 年 2 月 6 日
Thank you very much
I got it now
Jan
Jan 2019 年 4 月 8 日
amir baig found a typo: "qplus" -> "@plus".
Thanks!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by