Leonardo
Leonardo

Reputation: 11

How to collect the pixel from a line drawn over an image?

I have a grayscale image that I have drawn 4 lines using cv2:

Steel microstructure

But now I need to collect the pixel values along the lines, creating a "line profile", creating four lists with the values from left to write or top to bottom.

How can I do this?

import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img

#defines a scale factor
escala=0.7
cinza_esc = cv2.resize(cinza,None,fx=escala,fy=escala,interpolation=cv2.INTER_LINEAR)

#collect the dimensions of the image
xdim=cinza_esc.shape[1]
ydim=cinza_esc.shape[0]
se=(0,0);ie=(xdim,0);sd=(0,ydim);id=(xdim,ydim)

#line and text attr
cor = (0,0,0) #define a cor (tons de cinza)
fonte = cv2.FONT_HERSHEY_SIMPLEX
tamanho=int(xdim/500)
tipo_lh=cv2.LINE_4

#create the lines
cv2.line(cinza_esc, sd, ie, cor, 2)
cv2.line(cinza_esc, se, id, cor, 2)
cv2.line(cinza_esc, (0,int(ydim/2)), (xdim,int(ydim/2)), cor, 2)
cv2.line(cinza_esc, (int(xdim/2),0), (int(xdim/2),ydim), cor, 2)

#presents image
cv2.imshow("Imagem com as linhas", cinza_esc)

cv2.waitKey(0)
cv2.destroyAllWindows()

Upvotes: 1

Views: 2448

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 208003

You don't actually need to draw the line at all.

If you use skimage.draw.line it will give you a list of the points on the line.

Upvotes: 1

Related Questions