lydia-441
lydia-441

Reputation: 35

Is there a Python equivalent for MATLAB's 'improfile' function?

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

Answers (1)

gehbiszumeis
gehbiszumeis

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 skimages 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

enter image description here

Proof:

>>> np.array_equal(p, i)
True

Upvotes: 2

Related Questions