I’m analyzing some images, and in the course of my project I had to generate plots of the intensity of the green channel along a particular row of an image (as determined by the mouse position). So basically I take the entire row where the mouse pointer is placed and plot how the green channel changes along that row. Here’s the relevant parts of the code I wrote –
cv2image = cv2.imread(path)
if 0 <= y < cv2image.shape[0]: #y is the y-position of the mouse pointer
horizontal_channel = cv2image[y, :, 1] #1 corresponding to green from BGR
horizontal_pixel_coords = range(cv2image.shape[1])
ax2.plot(horizontal_pixel_coords, horizontal_channel, color = 'green')
The code itself is working perfectly, but here’s the kind of plot I’m getting –
Here’s the part at the top zoomed in –
I’m trying to smooth out this plot so that the layers are clear and straight, visible as somewhat straighter lines without so much fluctuation. Is there any way I can process my image or denoise the plot so that I get cleaner graphs?
ETA:
This is a rough idea of what I would like my graph to look like. (Obviously I want something that can be generalized to create such levels for other similar plots).
Here’s the I’ve used –
19