寻找苹果图片的不同图像分割方法

问题描述 投票:1回答:1

我有浸泡在碘溶液中的苹果片的图片。目标是将苹果分成感兴趣的各个区域,并评估每个区域的淀粉水平。这是针对学校项目的,因此我的目标是测试不同的细分方法,并客观地找到最佳解决方案,无论是单一技术还是多种技术的组合。

问题是,到目前为止,我只采用一种方法。该方法正在使用HoughCircles。我最初计划使用分水岭方法,形态学运算或简单的阈值处理。当我无法修改其中任何一个以使其工作时,该计划失败了。

原始图像看起来与此相似,但苹果的阴影深浅不一

<<

我曾尝试使用具有HSV值的cv2.inRange删除背景托盘,但不适用于深色苹果。

这是HoughCircles在原始图像上产生的效果,同时应用了灰度和中间模糊,还尝试了托盘遮罩。

<< 。“>

非常感谢您对下一步的建议或指示。如果可以,我可以提供正在使用的代码。

谢谢!

编辑1:添加一些代码并澄清问题

感谢您的回复。我真正的问题是,该场景是否还有其他适合的细分方法?我想尝试几种不同的方法,并比较大量照片的结果。我接下来要尝试的是使用k均值分割。另外,我还将在下面添加一些代码以显示到目前为止我已经尝试过的内容。

HSV颜色过滤

import cv2 import numpy as np # Load image image = cv2.imread('ApplePic.jpg') # Set minimum and max HSV values to display lower = np.array([0, 0, 0]) upper = np.array([105, 200, 255]) # Create HSV Image and threshold into a range. hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower, upper) maskedImage = cv2.bitwise_and(image, image, mask=mask) # Show Image cv2.imshow('HSV Mask', image) cv2.waitKey(0)

HoughCircles

# import the necessary packages
import numpy as np
import argparse
import cv2
import os

directory = os.fsencode('Photos\\Sample N 100')

for file in os.listdir(directory):

    filename = os.fsdecode(file)

    if filename.endswith('.jpg'):
        # Load the image
        image = cv2.imread('Photos\\Sample N 100\\' + filename)

        # Calculate scale
        scale_factor = 800 / image.shape[0]
        width = int(image.shape[1] * scale_factor)
        height = 800
        dimension = (width, height)
        min_radius = int((width / 10) * .8)
        max_radius = int((width / 10) * 1.2)

        # Resize image
        image = cv2.resize(image, dimension, interpolation=cv2.INTER_AREA)

        # Copy Image 
        output = image.copy()

        # Grayscale Image
        gray = cv2.medianBlur(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), 5)

        # Detect circles in image
        circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, min_radius * 2, 4, 60, 20,  min_radius, max_radius)

        # ensure at least some circles were found
        if circles is not None:
            # convert the (x, y) coordinates and radius of the circles to integers
            circles = np.round(circles[0, :]).astype("int")
            # loop over the (x, y) coordinates and radius of the circles
            for (x, y, r) in circles:
                # draw the circle in the output image, then draw a rectangle
                # corresponding to the center of the circle
                cv2.circle(output, (x, y), r, (0, 255, 0), 4)
                cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
                cv2.putText(output, '(' + str(x) + ',' + str(y) + ',' + str(r) + ')', (x, y),
                        cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, 255)


            # show the output image
            cv2.imshow("output", np.hstack([image, output, maskedImage]))
            cv2.waitKey(0)
        continue
    else:
        continue

我有浸泡在碘溶液中的苹果片的图片。目标是将苹果分成感兴趣的各个区域,并评估每个区域的淀粉水平。这是...

python opencv computer-vision image-segmentation hough-transform
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.