Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
固体颗粒的分水岭分割问题 我有一个问题,关于如何检测图像中的边界 土壤颗粒和测量这些边界的面积 分水岭分割算法如下所示,我将其用于 然而,彩色图像我发现了一种更好的边缘检测方法 使用整体嵌套边缘检测的算法,该算法提供了更好的 结果比精明的边缘检测。然而,我的主要问题是 涉及如何在获得图像的这些锐利边缘后使用此图像 粒子可以直接获得图像中的边界区域 使用python包中的任何内置函数_Python_Opencv - Fatal编程技术网

固体颗粒的分水岭分割问题 我有一个问题,关于如何检测图像中的边界 土壤颗粒和测量这些边界的面积 分水岭分割算法如下所示,我将其用于 然而,彩色图像我发现了一种更好的边缘检测方法 使用整体嵌套边缘检测的算法,该算法提供了更好的 结果比精明的边缘检测。然而,我的主要问题是 涉及如何在获得图像的这些锐利边缘后使用此图像 粒子可以直接获得图像中的边界区域 使用python包中的任何内置函数

固体颗粒的分水岭分割问题 我有一个问题,关于如何检测图像中的边界 土壤颗粒和测量这些边界的面积 分水岭分割算法如下所示,我将其用于 然而,彩色图像我发现了一种更好的边缘检测方法 使用整体嵌套边缘检测的算法,该算法提供了更好的 结果比精明的边缘检测。然而,我的主要问题是 涉及如何在获得图像的这些锐利边缘后使用此图像 粒子可以直接获得图像中的边界区域 使用python包中的任何内置函数,python,opencv,Python,Opencv,import cv2 import math import numpy as np from skimage.feature import peak_local_max from skimage.morphology import watershed from scipy import ndimage import xlwt from xlwt import Workbook wb = Workbook() sheet1 = wb.add_sheet('Sheet 1') n = 1 # Loa

import cv2
import math
import numpy as np
from skimage.feature import peak_local_max
from skimage.morphology import watershed
from scipy import ndimage
import xlwt
from xlwt import Workbook
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
n = 1
# Load in image, convert to gray scale, and Otsu's threshold
image = cv2.imread('gravels1_out.jpg')
# image = cv2.medianBlur(image, 7)
# kernel = np.ones((5,5),np.float32)/36
# image = cv2.filter2D(image,-1,kernel)
# cv2.imshow('img',image)
# cv2.waitKey()
# exit()
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
areas =[]
# Compute Euclidean distance from every binary pixel
# to the nearest zero pixel then find peaks
distance_map = ndimage.distance_transform_edt(image)
local_max = peak_local_max(distance_map, indices=False, min_distance=20, labels=image)

# Perform connected component analysis then apply Watershed
markers = ndimage.label(local_max, structure=np.ones((3, 3)))[0]
labels = watershed(-distance_map, markers, mask=image)

# Iterate through unique labels
total_area = 0
for label in np.unique(labels):
    if label == 0:
        continue

    # Create a mask
    mask = np.zeros(gray.shape, dtype="uint8")
    mask[labels == label] = 255
    # Find contours and determine contour area
    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    c = max(cnts, key=cv2.contourArea)
    area = cv2.contourArea(c)
    if area > 20:
        areas.append(area)
    print('polygon number ', n , 'of area ',area)
    n+=1
    cv2.drawContours(image, [c], -1, (36,255,12), 2)
cal_list=[]
for a in areas:
    b = a/29700
    cal_list.append(b)

row = 1
col = 0
gamma = 1.7
W =[]
cum = 0
for item in cal_list:
    r = 10*((item/math.pi)**0.5)
    v = (4/3)*math.pi*r**3
    w = gamma*v
    W.append(w)
    for c in W:
        cum = cum + c
    sheet1.write(row, col, item)
    sheet1.write(row,col+1,r)
    sheet1.write(row,col+2,v)
    sheet1.write(row, col + 3, w)
    sheet1.write(row, col + 4,cum)
    row+=1

wb.save('SAMPLE A .xls')
print('MAXIMUM VALUE OF AREAS DETECTED ', max(cal_list))
print('MINUMUM VALUE OF AREAS DETECTED ', min(cal_list))
print('Total number of polygons detected = ' , n)
cv2.imshow('image', image)
cv2.waitKey()