1 Star 0 Fork 0

娄维尧/Unsupervised-Segmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo_pre_seg__felz_slic.py 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
Yonv 提交于 2019-06-19 16:26 . demo x3
import cv2
from skimage import segmentation
mark_boundaries = segmentation.mark_boundaries
def press_wasdqe_to_adjust_parameter_of_felz(img):
paras = [64, 0.5, 128] # pieces
# paras = [1, 0.8, 20] # default
act_dict = {0: (0, 1.0)}
act_dict.update(zip([119, 97, 113], [(i, 1.2) for i in range(len(paras))], )) # _KeyBoard: W A Q
act_dict.update(zip([115, 100, 101], [(i, 0.8) for i in range(len(paras))], )) # KeyBoard: S D E
key = 0
while True:
if key != -1:
i, multi = act_dict[key]
paras[i] *= multi
print(key, paras)
seg_map = segmentation.felzenszwalb(img,
scale=int(paras[0]),
sigma=paras[1],
min_size=int(paras[2]))
show = mark_boundaries(img, seg_map)
cv2.imshow('', show)
wait_time = 1
else:
wait_time = 100
key = cv2.waitKey(wait_time)
break
cv2.imwrite('tiger_felz.jpg', show * 255)
def press_wasdqe_to_adjust_parameter_of_slic(img):
paras = [100, 10000, 10] # pieces
# paras = [100, 10, 10] # default
# paras = [16, 64, 6] # appropriate
act_dict = {0: (0, 1.0)}
act_dict.update(zip([119, 97, 113], [(i, 1.2) for i in range(len(paras))], )) # _KeyBoard: W A Q
act_dict.update(zip([115, 100, 101], [(i, 0.8) for i in range(len(paras))], )) # KeyBoard: S D E
key = 0
while True:
if key != -1:
i, multi = act_dict[key]
paras[i] *= multi
print(key, paras)
seg_map = segmentation.slic(img,
compactness=int(paras[0]),
n_segments=int(paras[1]),
max_iter=int(paras[2]), )
show = mark_boundaries(img, seg_map)
cv2.imshow('', show)
wait_time = 1
else:
wait_time = 100
key = cv2.waitKey(wait_time)
# break
# cv2.imwrite('tiger_slic.jpg', show * 255)
if __name__ == '__main__':
image = cv2.imread('image/tiger.jpg')
press_wasdqe_to_adjust_parameter_of_felz(image)
# press_wasdqe_to_adjust_parameter_of_slic(image)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lou_wei_yao/Unsupervised-Segmentation.git
git@gitee.com:lou_wei_yao/Unsupervised-Segmentation.git
lou_wei_yao
Unsupervised-Segmentation
Unsupervised-Segmentation
master

搜索帮助