Sum Elements Along A Line Of Numpy Array
I have a big matrix of shape (977,699). I would like to compute the sum of the elements along a line that starts approximately from the center of the matrix. The angle of the line
Solution 1:
Maybe the radon transform contains the projection you are looking for or possibly is what you are describing. An example with code for the transform along with some reconstruction methods can be found in the scikit-image documentation here
Try copying and pasting this:
import numpy as np
from skimage.transform import radon
image = np.zeros([100, 100])
image[25:75, 25:50] = np.arange(25)[np.newaxis, :]
angles = np.linspace(0., 180., 10)
# If the important part of the image is confined # to a circle in the middle use circle=True
transformed = radon(image, theta=angles)
import matplotlib.pyplot as plt
plt.matshow(image)
plt.matshow(transformed.T)
plt.show()
The transformed
matrix contains one column per angle and all projection lines in the direction encoded this angle over the whole image. If your image is circular, it is useful to specify circle=True
so that it does not project the borders.
Post a Comment for "Sum Elements Along A Line Of Numpy Array"