最近无聊开始自学CV方向,从 Computer Vision:Algorithms and Applications 开始入门
文中提到了 Markov Random Fields
于是去了解了一下相关知识,为了巩固理解就进行了图像分割的应用
相关知识参考链接:https://blog.csdn.net/beattodeath/article/details/54630690
代码参考:https://blog.csdn.net/sxk20091111/article/details/80758050
代码是对上述参考链接的代码进行修改,使其能跑通。而第二个参考链接的代码其实就是第一个链接的python版本
import cv2
import numpy as np
img = cv2.imread('1.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #将图片二值化,彩色图片该方法无法做分割
img = gray
img_double = np.array(img, dtype = np.float64)
cluster_num = 2
max_iter =200
label=np.random.randint(1, cluster_num + 1, size = img_double.shape)
iter=0
f_u =