我正在开发一个应用程序来检测病变区域,为此我使用抓取来检测 ROI 并从图像中删除背景。但是,在某些图像中,它运行不佳。他最终没有很好地确定感兴趣区域的边界。分水岭可以更好地识别此类工作的边缘,但是我在从抓地到分水岭的过渡过程中遇到了困难。在处理抓取之前,用户使用 touchevent 在感兴趣的图像(伤口区域)周围标记一个矩形,以方便算法的工作。如下图。
但是,使用其他伤口图像,分割效果不佳,显示出 ROI 检测的缺陷。
在应用程序中使用抓取的图像
在桌面中使用分水岭的图像
这是代码:
private fun extractForegroundFromBackground(coordinates: Coordinates, currentPhotoPath: String): String {
// TODO: Provide complex object that has both path and extension
val width = bitmap?.getWidth()!!
val height = bitmap?.getHeight()!!
val rgba = Mat()
val gray_mat = Mat()
val threeChannel = Mat()
Utils.bitmapToMat(bitmap, gray_mat)
cvtColor(gray_mat, rgba, COLOR_RGBA2RGB)
cvtColor(rgba, threeChannel, COLOR_RGB2GRAY)
threshold(threeChannel, threeChannel, 100.0, 255.0, THRESH_OTSU)
val rect = Rect(coordinates.first, coordinates.second)
val fg = Mat(rect.size(), CvType.CV_8U)
erode(threeChannel, fg, Mat(), Point(-1.0, -1.0), 10)
val …
Run Code Online (Sandbox Code Playgroud) 我正在努力识别皮肤斑点.为此,我使用了许多具有不同噪声的图像.这些噪音中的一个是毛发,因为我在污渍区域(ROI)上有毛发的图像.如何减少或消除这些类型的图像噪音?
下面的代码减少了毛发的区域,但不会去除感兴趣区域(ROI)上方的毛发.
import numpy as np
import cv2
IMD = 'IMD436'
# Read the image and perfrom an OTSU threshold
img = cv2.imread(IMD+'.bmp')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
# Remove hair with opening
kernel = np.ones((2,2),np.uint8)
opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)
# Combine surrounding noise with ROI
kernel = np.ones((6,6),np.uint8)
dilate = cv2.dilate(opening,kernel,iterations=3)
# Blur the image for smoother ROI
blur = cv2.blur(dilate,(15,15))
# Perform another OTSU threshold and search for biggest contour
ret, thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) …
Run Code Online (Sandbox Code Playgroud) 我正在为 android studio 使用 opencv。我对此几乎没有经验,所以我请求帮助从图像中删除背景并只留下感兴趣的区域。我正在处理伤口图像,我只想在应用程序屏幕上留下伤口区域,如下图所示。
我正在使用 kotlin 并且我设法执行图像的分水岭,只是从图像的背景中遗漏了伤口区域,有人可以帮助我吗?
private fun threashold(){
val width = imgBmpDefault?.getWidth()!!
val height = imgBmpDefault?.getHeight()!!
val rgba = Mat()
val gray_mat = Mat()
val threeChannel = Mat()
Utils.bitmapToMat(imgBmpDefault, gray_mat)
Imgproc.cvtColor(gray_mat, rgba, Imgproc.COLOR_RGBA2RGB)
Imgproc.cvtColor(rgba, threeChannel, Imgproc.COLOR_RGB2GRAY)
Imgproc.threshold(threeChannel, threeChannel, 100.0, 255.0, Imgproc.THRESH_OTSU)
val fg = Mat(rgba.size(), CvType.CV_8U)
Imgproc.erode(threeChannel, fg, Mat(), Point(-1.0, -1.0), 2)
val bg = Mat(rgba.size(), CvType.CV_8U)
Imgproc.dilate(threeChannel, bg, Mat(), Point(-1.0, -1.0), 3)
Imgproc.threshold(bg, bg, 1.0, 128.0, Imgproc.THRESH_BINARY_INV)
val markers = Mat(rgba.size(), CvType.CV_8U, Scalar(0.0))
Core.add(fg, bg, markers) …
Run Code Online (Sandbox Code Playgroud) 我正在研究图像颜色识别,所以我将 RGB 图像转换为 Lab,因为它是最接近人类视觉的颜色空间。之后,我获得了 Lab 的 3 个通道中的每一个,我想在 3D 图形中绘制我在转换后的图像中识别的颜色变化。如何使用图像的颜色绘制图形?
import cv2
import numpy as np
import urllib
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.pyplot as plt
# Load an image that contains all possible colors.
request = urllib.urlopen('IMD021.png')
image_array = np.asarray(bytearray(request.read()), dtype=np.uint8)
image = cv2.imdecode(image_array, cv2.CV_LOAD_IMAGE_COLOR)
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
l_channel,a_channel,b_channel = cv2.split(lab_image)
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.scatter(l_channel, a_channel, b_channel, marker='o', facecolors=cv2.cvtColor(image, cv2.COLOR_BGR2RGB).reshape(-1,3)/255.)
ax.set_xlabel('L')
ax.set_ylabel('A')
ax.set_zlabel('B')
fig.add_axes(ax)
#plt.savefig('plot-15.png')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我正致力于提取图像特征,我正在尝试识别某个图像是否对称.我正在使用opecv - python来开发这项工作.
下面的代码用于识别感兴趣区域的中心和直径.你怎么知道这个图像是否对称?
import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredText
IMG = '015'
thresh = cv2.imread(IMD+'.png',0)
_, contours,hierarchy = cv2.findContours(thresh,2,1)
print (len(contours))
cnt = contours
for i in range (len(cnt)):
(x,y),radius = cv2.minEnclosingCircle(cnt[i])
center = (int(x),int(y))
radius = int(radius)
cv2.circle(thresh,center,radius,(0,255,0),2)
print ('Circle: ' + str(i) + ' - Center: ' + str(center) + ' - Radius: ' + str(radius))
plt.text(x-21, y+15, '+', fontsize=25, color = 'red')
plt.text(10, -10, 'Centro: '+str(center), fontsize=11, color …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,该应用程序选择伤口图像并将其显示在应用程序屏幕上。以此,用户标记伤口的感兴趣区域,以便稍后算法可以识别和处理感兴趣区域。我正在使用 lib 实现 'com.github.gcacace: signature-pad: 1.2.1' 来划分区域,然后保存屏幕的“printscreen”,这样我就可以将标记与图像一起保存伤口。我希望图像看起来如何
但是,我想根据伤口的图像剪切打印屏幕以发送到服务器以处理图像。谁能帮我剪下标记后的伤口图像。
private fun saveImage(myBitmap: Bitmap?): String? {
try {
// image naming and path to include sd card appending name you choose for file
val mPath = Environment.getExternalStorageDirectory().toString() + "/imagesignature.jpg"
// create bitmap screen capture
val v1 = window.decorView.rootView
v1.isDrawingCacheEnabled = true
val bitmap = Bitmap.createBitmap(v1.drawingCache)
v1.isDrawingCacheEnabled = false
val imageFile = File(mPath)
val outputStream = FileOutputStream(imageFile)
val quality = 100
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)
outputStream.flush()
outputStream.close()
//setting screenshot in imageview
val filePath …
Run Code Online (Sandbox Code Playgroud)