Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 RandomWalker分割算法产生与初始种子相同的分割结果 我有一张医学图像,我试着在里面分割一个特定的区域 经过几个常规图像处理步骤后,我能够定位该区域,并设法获得分割种子,但当我尝试应用RandomWalker算法时,我没有得到一个好的分割 你能告诉我这里的问题是什么,怎么解决吗_Python_Image Processing_Image Segmentation_Scikit Image_Random Walk - Fatal编程技术网

Python RandomWalker分割算法产生与初始种子相同的分割结果 我有一张医学图像,我试着在里面分割一个特定的区域 经过几个常规图像处理步骤后,我能够定位该区域,并设法获得分割种子,但当我尝试应用RandomWalker算法时,我没有得到一个好的分割 你能告诉我这里的问题是什么,怎么解决吗

Python RandomWalker分割算法产生与初始种子相同的分割结果 我有一张医学图像,我试着在里面分割一个特定的区域 经过几个常规图像处理步骤后,我能够定位该区域,并设法获得分割种子,但当我尝试应用RandomWalker算法时,我没有得到一个好的分割 你能告诉我这里的问题是什么,怎么解决吗,python,image-processing,image-segmentation,scikit-image,random-walk,Python,Image Processing,Image Segmentation,Scikit Image,Random Walk,代码: Random walker仅将标签从标记扩展到标签为0的区域。最终得到的图像除原始正方形中的2个图像外,其他所有位置都只包含1个图像。这是因为标签2无处可扩展:它被1包围 我可以使用以下工具稍微修改分段: border=71 环绕=( (扩张(标记,np.ONE((边框,边框))==2) ^(标记==2) ) 标记[环绕]=0 标签=随机(img,标记)*(img!=0) 它肯定还不完美。除此之外,您还需要使用边框大小以及random\u walker的beta=和tol=参数 #

代码: Random walker仅将标签从标记扩展到标签为0的区域。最终得到的图像除原始正方形中的2个图像外,其他所有位置都只包含1个图像。这是因为标签2无处可扩展:它被1包围

我可以使用以下工具稍微修改分段:

border=71
环绕=(
(扩张(标记,np.ONE((边框,边框))==2)
^(标记==2)
)
标记[环绕]=0
标签=随机(img,标记)*(img!=0)

它肯定还不完美。除此之外,您还需要使用边框大小以及
random\u walker
beta=
tol=
参数

# import math
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from skimage.feature import canny
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.draw import circle_perimeter
from skimage.segmentation import watershed, random_walker, active_contour
import skimage.filters as filters

# Read image
img = cv.imread("CT.png")

# Get image center coordinates
img_center = (img.shape[0]//2, img.shape[1]//2)

# Edge detector
edges = canny(img, sigma=2.0, low_threshold=19, high_threshold=57)

# Hough_circle
hough_radii = np.arange(29, 32, 1)
hough_res = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,total_num_peaks=4, min_xdistance=70,min_ydistance=200, threshold=0.25)

# Remove false-posite circle
sortX = np.argsort(cx)
cx = cx[sortX[:-1]]
cy = cy[sortX[:-1]]
radii = radii[sortX[:-1]]

#--------------------------------------
# get the closest circle to the centre 
#--------------------------------------
dist = []
for idx in range(len(cx)):
    dist.append(abs(img_center[1]-cx[idx])+abs(img_center[0]-cy[idx]))
sortD = np.argsort(dist)
Cx = cx[sortD[0]]
Cy = cy[sortD[0]]
radius = radii[sortD[0]]

markers = np.ones(img.shape, dtype=np.uint)
markers[img==0] = 0
markers[Cy-radius//2:Cy+radius//2, Cx-radius//2:Cx+radius//2] = 2
# markers[(Cy-radius//2)+1:(Cy+radius//2)-1, (Cx-radius//2)+1:(Cx+radius//2)-1] = 0
#---------------------------------
labels = random_walker(img, markers)

# print(labels.shape)
# Plot results
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 3.2),
                                    sharex=True, sharey=True)
ax1.imshow(img, cmap='gray')
ax1.axis('off')
ax1.set_title('Noisy data')
ax2.imshow(markers, cmap='magma')
ax2.axis('off')
ax2.set_title('Markers')
ax3.imshow(labels, cmap='gray')
ax3.axis('off')
ax3.set_title('Segmentation')

fig.tight_layout()
plt.show()
#======================================