1 回答

TA貢獻1824條經驗 獲得超5個贊
我不熟悉您的圖像類型,但希望可以在 Numpy 和 OpenCV 方面幫助您。
#!/usr/bin/env python3
import pylas
import cv2
import numpy as np
# Open file
las = pylas.read('W2.las')
# Extract all the red values into a Numpy array, likewise green and blue
R = las.points["red"]
G = las.points["green"]
B = las.points["blue"]
# Make a Numpy image by stacking the RGB values and converting to uint8
BGR = (np.dstack((B,G,R))>>8).astype(np.uint8)
# Convert to HSV
HSV = cv2.cvtColor(BGR, cv2.COLOR_BGR2HSV)
# Define lower and uppper limits of what we call "green"
range_lo = np.array([70,30,30])
range_hi = np.array([90,255,255])
# Mask image to only select greens
mask = cv.inRange(HSV,range_lo,range_hi)
# Change image to red where we found green
image[mask>0]=(0,0,255)
cv.imwrite("result.png",image)
目前,我不知道圖像的形狀,所以它是一條 4400 萬像素的長線,但它只需要 areshape()即可使其正確。請注意,每個 True/False 值都mask將成為像素列表中的索引,并指示該像素是否為綠色。
您可能必須使用參數的下限值和上限值- 請參閱我的range
答案。
Stack Overflow 用戶 @nathancy 在這里制作了一個相當簡潔的 HSV 顏色選擇器,帶有滑塊。
添加回答
舉報