如何使用K-means聚类来分割彩色图像?

时间:2017-01-09 15:09:57

标签: matlab image-processing k-means image-segmentation

我正在开发一个通过k-means聚类执行分段的项目。我必须对K = [2,3,4,... K-max]应用K-means聚类,并计算每个点到其聚类中心的平均距离。此外,当我切换到K * + 1时,我必须确定该距离变化不大的K * .Kmax = 20.

据我写下来的代码如下。我的第一个问题出现了我做错了吗?

`| ave_dist(K*) - ave_dist(K*+1) |< THR_K.  THR_K = 100` 

1)我如何绘制到聚类中心的平均距离作为K的函数?

2)我如何确定

的最小K *
$sql = "CREATE TABLE fixtureDetails
(
fixtureID INT(5) NOT NULL AUTO INCREMENT,
opponent VARCHARD(30) NOT NULL,
date DATE
away BOOLEAN,
sportID INT
refereeID INT,
PRIMARY KEY (fixtureID),
FOREIGN KEY (sportID) REFERENCES sport(sportID),
FOREIGN KEY (refereeID) REFERENCES referee(refereeID)
)";

$sql1 = "SELECT * FROM fixtureDetails";
if ($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result)>0){
        echo "<table>";
            echo "<tr>";
                echo "<th>fixtureID</th>";
                echo "<th>opponent</th>";
                echo "<th>date</th>";
                echo "<th>away</th>";
                echo "<th>sportID</th>";
                echo "<th>refereeID</th>";
            echo"</tr>";
        while($row = mysqli_fetch_array($result)){
            echo "<tr>";
                echo "<td>" . $row['fixtureID'] . "</td>";
                echo "<td>" . $row['opponent'] . "</td>";
                echo "<td>" . $row['date'] . "</td>";
                echo "<td>" . $row['away'] . "</td>";
                echo "<td>" . $row['sportID'] . "</td>";
                echo "<td>" . $row['refereeID'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
        mysqli_free_result($result);
    } else {
        echo "No records matching your query found.";
    }
} else {
    echo "ERROR: could not execute $sql1. " . mysqli_error($link);
}

谢谢。

1 个答案:

答案 0 :(得分:0)

第一个问题:您正在构建可以直接使用ave_dist

的向量plot(ave_dist)

第二个问题:您可以使用findindex = find(abs(ave_dist(1:end-1)-ave_dist(2:end)) <= 100,1,'first')