小编Túl*_*cha的帖子

如何删除该图像的特定颜色?

我想删除Brain Image图像的所有米色,从而产生其他图像(棕色、绿色、黄色和红色)。我尝试使用删除白色背景的相同代码来执行此操作,仅修改 RGB 代码,但没有成功。(抱歉,如果帖子中犯了一些错误)

import cv2 
import numpy as np

# Read image
img = cv2.imread(r'D:\PY\mk1\mk1\sagitale1.png')
hh, ww = img.shape[:2]

# threshold on white
# Define lower and uppper limits
lower = np.array([101, 69, 51])
upper = np.array([255, 171, 142])

# Create mask to only select black
thresh = cv2.inRange(img, lower, upper)

# apply morphology
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(20,20))
morph = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)

# invert morp image
mask = 255 - thresh

# apply mask to image
result …
Run Code Online (Sandbox Code Playgroud)

python opencv numpy

1
推荐指数
1
解决办法
254
查看次数

标签 统计

numpy ×1

opencv ×1

python ×1