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

조회 수: 3 (최근 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개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by