gpt4 book ai didi

image - 突出显示具有不同颜色图像的区域及其周围区域

转载 作者:行者123 更新时间:2023-12-01 00:09:29 26 4
gpt4 key购买 nike

我刚刚开始使用计算机视觉和 OpenCV。

我正在处理 MRI 大脑图像,我想知道是否有过滤器或其他东西可以让我分割我在此图像上标记为红色的区域:

enter image description here

这是原图:



是的,我知道有很多深度学习解决方案来分割这种网络,但我想知道,因为我是新手,是否有一个过滤器来突出我所包围的这些区域。

问题是:

是否有过滤器或其他东西可以突出显示我包围的区域?

这就是我想要得到的:

enter image description here

最佳答案

观察到您要提取的部分具有特定颜色,我们可以使用颜色阈值来隔离对象。您没有指定语言,所以我将使用 Python 进行演示。这个想法是使用 cv2.inRange() 确定下/上颜色范围然后颜色阈值.我们将图像转换为 HSV 格式,然后使用此范围生成二进制分段掩码

lower = np.array([0, 0, 118])
upper = np.array([179, 255, 202])



import numpy as np
import cv2

# Color threshold
image = cv2.imread('1.png')
original = image.copy()
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower = np.array([0, 0, 118])
upper = np.array([179, 255, 202])
mask = cv2.inRange(hsv, lower, upper)
result = cv2.bitwise_and(original,original,mask=mask)

cv2.imshow('mask', mask)
cv2.imshow('result', result)
cv2.imshow('original', original)
cv2.waitKey()

您可以将此颜色阈值脚本与轨迹栏一起使用来微调上下颜色范围
import cv2
import numpy as np

def nothing(x):
pass

# Load image
image = cv2.imread('1.png')

# Create a window
cv2.namedWindow('image')

# Create trackbars for color change
# Hue is from 0-179 for Opencv
cv2.createTrackbar('HMin', 'image', 0, 179, nothing)
cv2.createTrackbar('SMin', 'image', 0, 255, nothing)
cv2.createTrackbar('VMin', 'image', 0, 255, nothing)
cv2.createTrackbar('HMax', 'image', 0, 179, nothing)
cv2.createTrackbar('SMax', 'image', 0, 255, nothing)
cv2.createTrackbar('VMax', 'image', 0, 255, nothing)

# Set default value for Max HSV trackbars
cv2.setTrackbarPos('HMax', 'image', 179)
cv2.setTrackbarPos('SMax', 'image', 255)
cv2.setTrackbarPos('VMax', 'image', 255)

# Initialize HSV min/max values
hMin = sMin = vMin = hMax = sMax = vMax = 0
phMin = psMin = pvMin = phMax = psMax = pvMax = 0

while(1):
# Get current positions of all trackbars
hMin = cv2.getTrackbarPos('HMin', 'image')
sMin = cv2.getTrackbarPos('SMin', 'image')
vMin = cv2.getTrackbarPos('VMin', 'image')
hMax = cv2.getTrackbarPos('HMax', 'image')
sMax = cv2.getTrackbarPos('SMax', 'image')
vMax = cv2.getTrackbarPos('VMax', 'image')

# Set minimum and maximum HSV values to display
lower = np.array([hMin, sMin, vMin])
upper = np.array([hMax, sMax, vMax])

# Convert to HSV format and color threshold
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower, upper)
result = cv2.bitwise_and(image, image, mask=mask)

# Print if there is a change in HSV value
if((phMin != hMin) | (psMin != sMin) | (pvMin != vMin) | (phMax != hMax) | (psMax != sMax) | (pvMax != vMax) ):
print("(hMin = %d , sMin = %d, vMin = %d), (hMax = %d , sMax = %d, vMax = %d)" % (hMin , sMin , vMin, hMax, sMax , vMax))
phMin = hMin
psMin = sMin
pvMin = vMin
phMax = hMax
psMax = sMax
pvMax = vMax

# Display result image
cv2.imshow('image', result)
if cv2.waitKey(10) & 0xFF == ord('q'):
break

cv2.destroyAllWindows()

关于image - 突出显示具有不同颜色图像的区域及其周围区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60152862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com