You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

植物上皮细胞边缘检测后极坐标插值尖峰问题求助

植物上皮细胞微CT图像边缘平滑问题

我正在开展植物上皮细胞分割工作,目标是从微CT扫描图像中分离细胞并进行各类指标分析。目前已完成细胞分割与Canny边缘检测,但检测到的边缘存在缺口,填充部分呈锯齿状。

为解决该问题,我尝试将坐标转换为极坐标,计算插值值后通过线性插值生成平滑曲线,再转回笛卡尔坐标,但转回后形状出现异常尖峰。我先后尝试对x值升序排序、更换插值类型、使用scipy.findpeaks去除尖峰,但findpeaks仅适用于特定形状,不具备通用性。该问题已困扰我两周,作为Python新手,希望能得到相关帮助。

附上相关代码及示例图像说明:

##Canny Edge Detection of Edges##

#Get edge of image
#dilation = cv2.dilate(props[150].image,kernel=K,iterations = 1)
img_edges = feature.canny(props[150].image, mode='constant') #, sigma=.1)

#Sanity check
#plt.imshow(img_edges)

#Get coordinates
coords = np.argwhere(img_edges)

#Rearrange coords
coordinates = np.column_stack((coords[:,0], coords[:,1]))
sorted_coordinates = coordinates[coordinates[:, 0].argsort()]

#Finding the centroid 
xX = [p[0] for p in coords]
yY = [p[1] for p in coords]
centroid = (sum(xX) / len(coords), sum(yY) / len(coords)) #xX,yY
(x_cent, y_cent) = centroid

#Plotting shape
plt.plot(coords[:,0],coords[:,1],".") #y,x
plt.scatter(sorted_coordinates[:,0],sorted_coordinates[:,1])
plt.show()

##Converting to polar coordinates##
#Defining Conversion
def cart2pol(x, y):
    rho = np.sqrt(x**2 + y**2)
    phi = np.arctan2(y, x)
    return(rho, phi)

#Calculating distances from contours
rs, rhos = [], []
for i in range(0,len(coords),2): #5
    #r, rho = cart2pol(coords[i,0]-props[150].centroid_local[0], coords[i,1]-props[150].centroid_local[1])
    r, rho = cart2pol(coords[i,0]-centroid[0], coords[i,1]-centroid[1])
    rhos.append(rho)
    rs.append(r)
    
#Ensuring phi-values are in ascending order
L = sorted(zip(rhos,rs), key=operator.itemgetter(0)) #sorted(zip(rhos,rs), key=operator.itemgetter(0))
new_rho, new_r = zip(*L)

#plt.plot(new_x,new_y)
plt.scatter(new_rho, new_r, s=1) #, zorder=2)
plt.scatter(rhos, rs, s=1)
plt.title('Pre-interpolation')
plt.ylabel('r')
plt.xlabel('theta')
plt.show()

##Post-interpolation## 

# Convert the new_x and new_y lists to numpy arrays
new_x = np.array(new_rho) * 1
new_y = np.array(new_r) * 1

# Sort the new_x and new_y arrays based on new_x
sorted_indices = np.argsort(new_x)
sorted_x = new_x[sorted_indices]
sorted_y = new_y[sorted_indices]

# Create evenly spaced x-values for interpolation
interpolation_range = np.linspace(sorted_x.min(), sorted_x.max(), 1000)#110)

# Perform linear interpolation
linear_interpolation = interp1d(sorted_x, sorted_y, kind='linear')(interpolation_range)

# Plot the original data
plt.scatter(new_x, new_y, label='Original Data', c='black', s = 4)

# Plot the interpolated data
plt.plot(interpolation_range, linear_interpolation, c='r', label='Linear Interpolation')

# Set labels and title for the plot
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Linear Interpolation')

# Show legend
plt.legend()

# Display the plot
plt.show()

##Transforming back to Cartesian Coordinates##

def pol2cart(rho, phi):
    x = rho * np.cos(phi)
    y = rho * np.sin(phi)
    return(x, y)

x_cart,y_cart= pol2cart(linear_interpolation,interpolation_range)
xn_cart,yn_cart= pol2cart(Xn,Yn)

plt.plot(coords[:,0],coords[:,1],".",c='red',linewidth=1)
plt.plot(x_cart+centroid[0],y_cart+centroid[1], c='blue', linewidth=2) #73,73
#plt.plot(yn_cart,xn_cart, c='blue', linewidth=2) #73,73
fig1 = plt.gcf()
aspect_ratio = 1
fig1.set_size_inches(4, 4 / aspect_ratio) 
plt.show()

示例图像说明

  • 图1:Canny边缘检测得到的原始细胞边缘,存在明显缺口与锯齿状填充
  • 图2:极坐标转换前的边缘点分布情况
  • 图3:线性插值后的极坐标曲线结果
  • 图4:转回笛卡尔坐标后出现异常尖峰的平滑边缘

内容的提问来源于stack exchange,提问作者yippee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 13:14:57