Reputation: 935
I have an image of size 30 x 100
pixels.
How can I count how many pixels are there on the diagonal? can I just apply the Pythagorean theorem? but if yes, we may obtain float number of pixels. So how can I address this issue?
In addition, how can I extract automatically the x
and y
coordinate values of
each pixel on the diagonal?
I have written a MATLAB code for a square matrix which is very easy. But how can I generalize my code to include images of any size (not only square images)..
%suppose an image of size 100 x 100
image = rand(100,100);
n = length(image);
%extract how many pixels are there on the diagonal
diagonal_pixels = sqrt(n^2 + n^2);
%Get the x and y coordinates values of each diagonal pixel
for i = 1: n
x_coordinate_diag(i) = i;
y_coordinate_diag(i) = i;
end
Upvotes: 1
Views: 216
Reputation: 2598
You could use these steps to get the diagonal pixels
For example 50 x 100
j = 0 x 100 / 50 = 0
j = 1 x 100 / 50 = 2
j = 2 x 100 / 50 = 4
j = 50 x 100 / 50 = 100
Upvotes: 2