资源简介
该代码能够实现K均值聚类算法对彩色图像分割,在MATLAB下实现。
代码片段和文件信息
%function [mumask]=kmeans(imak)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% kmeans image segmentation
%
% Input:
% ima: grey color image
% k: Number of classes
% Output:
% mu: vector of class means
% mask: clasification image mask
% image:clasification image
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear;
k=4;
% check image
A=imread(‘C:\用户\NSM\桌面\NSM\2.jpg‘‘jpg‘);
%imshow(A);
B=rgb2gray(A);
%B=imread(‘C:\用户\NSM\桌面\NSM\4.jpg‘‘jpg‘);
imwrite(B‘C:\用户\NSM\桌面\NSM\22.jpg‘‘jpg‘);
ima=double(B);
copy=ima; % make a copy
ima=ima(:); % vectorize ima
mi=min(ima); % deal with negative
ima=ima-mi+1; % and zero values
s=length(ima);
% crea
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1893 2011-04-15 10:02 a7eeadc24bc0\kmeans.m
目录 0 2011-04-14 21:42 a7eeadc24bc0
----------- --------- ---------- ----- ----
1893 2
评论
共有 条评论