Reputation: 35
I'm trying to produce a Gaussian fit to profile the beam intensity of an image of a laser beam cross-section. I know how to do this easily with MATLAB's improfile
function, which lets me specify the line segment with my mouse and plots the intensity values versus the distance along the line segment. Is there a Python equivalent that will let me complete the same task?
Upvotes: 2
Views: 2896
Reputation: 3711
Yes, there is: Function profile_line
from the skimage.measure
package. I do not have the Image Processing Toolbox in MATLAB, so I cannot show the example also with MATLABs improfile
function, but it works the same way as skimage
s profile_line
.
For example:
import matplotlib.pyplot as plt
import numpy as np
from skimage.measure import profile_line
from skimage import io
# Load some image
I = io.imread('265173ab144040477cc4d41606b36cd6.jpg', as_gray=True)
# Extract intensity values along some profile line
p = profile_line(I, (45, 30), (160, 30))
# Extract values from image directly for comparison
i = I[45:161, 30]
plt.plot(i)
plt.ylabel('intensity')
plt.xlabel('line path')
plt.show()
In the profile intensity plot, both arrays are ontop of each other
Proof:
>>> np.array_equal(p, i)
True
Upvotes: 2