在彩色图像上画一条直线:
for item in lc_imglists:
img_ori = cv2.imread(item)
cv2.line(img_ori,(100,100),(1000,1000),(0,0,255),3)
imshow(img_ori,600,600,'img',True)
for item in lc_imglists:
img = cv2.imread(item)[:,0:2000,:]
img = np.flipud(img) # np.fliplr
cv2.line(img,(100,100),(1000,1000),(0,0,255),3)
imshow(img,600,600,'img',True)
图像中没有显示所画的红线,退而求其次,对每个通道进行翻转,再进行拼接:
for item in lc_imglists:
img = cv2.imread(item)[:,0:2000,:]
flag = True
if flag:
b,g,r = cv2.split(img)
b = np.fliplr(b)
g = np.fliplr(g)
r = np.fliplr(r)
img[:,:,0] = b
img[:,:,1] = g
img[:,:,2] = r
cv2.line(img,(100,100),(1000,1000),(0,0,255),3)
imshow(img,600,600,'img',True)
def CalcImgProjection(img):
rowProjection = np.mean(img, axis=0)
colProjection = np.mean(img, axis=1)
plt.figure()
plt.subplot(121)
plt.imshow(img, 'gray')
plt.title('img')
plt.subplot(222)
plt.plot(rowProjection, 'r*')
plt.title('row')
plt.subplot(224)
plt.plot(colProjection, 'go')
plt.title('col')
plt.show()
if __name__ == '__main__':
data = './datasets/lowcontrast_thread/'
type = '*.bmp'
imglists = glob.glob(data + type)
for item in imglists:
img = cv2.imread(item,0)[:,:2500]
CalcImgProjection(img)