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

3 Ansichten (letzte 30 Tage)
Pratik Oak
Pratik Oak am 5 Feb. 2018
Kommentiert: Jan am 8 Apr. 2019
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.

Akzeptierte Antwort

Jan
Jan am 5 Feb. 2018
Bearbeitet: Jan am 8 Apr. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by