kmeans-图像分割代码

上传人:ni****g 文档编号:470490581 上传时间:2022-08-09 格式:DOCX 页数:2 大小:10.85KB
返回 下载 相关 举报
kmeans-图像分割代码_第1页
第1页 / 共2页
kmeans-图像分割代码_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《kmeans-图像分割代码》由会员分享,可在线阅读,更多相关《kmeans-图像分割代码(2页珍藏版)》请在金锄头文库上搜索。

1、精品文档,仅供学习与交流,如有侵权请联系网站删除he = imread(02.png); % 读入图像imshow(he), title(H&E image);text(size(he,2),size(he,1)+15,.Image courtesy of Alan Partin, Johns Hopkins University, .FontSize,7,HorizontalAlignment,right);cform = makecform(srgb2lab); % 色彩空间转换lab_he = applycform(he,cform);ab = double(lab_he(:,:,2:3

2、); % 数据类型转换nrows = size(ab,1); % 求矩阵尺寸ncols = size(ab,2); % 求矩阵尺寸ab = reshape(ab,nrows*ncols,2); % 矩阵形状变换nColors = 3;% 重复聚类3次,以避免局部最小值cluster_idx cluster_center = kmeans(ab,nColors,distance,sqEuclidean, .Replicates,3);pixel_labels = reshape(cluster_idx,nrows,ncols); % 矩阵形状改变imshow(pixel_labels,); %

3、显示图像title(image labeled by cluster index); % 设置图像标题segmented_images = cell(1,3); % 细胞型数组rgb_label = repmat(pixel_labels,1 1 3); % 矩阵平铺for k = 1:nColorscolor = he;color(rgb_label = k) = 0;segmented_imagesk = color;endimshow(segmented_images1), % 显示处理后的图像title(objects in cluster 1); % 设置图像标题imshow(seg

4、mented_images2), % 显示处理后的图像title(objects in cluster 2); % 设置图像标题imshow(segmented_images3), % 显示处理后的图像title(objects in cluster 3); % 设置图像标题mean_cluster_value = mean(cluster_center,2);tmp, idx = sort(mean_cluster_value);blue_cluster_num = idx(1);L = lab_he(:,:,1);blue_idx = find(pixel_labels = blue_cl

5、uster_num);L_blue = L(blue_idx);is_light_blue = im2bw(L_blue,graythresh(L_blue); % 图像黑白转换nuclei_labels = repmat(uint8(0),nrows ncols); % 矩阵平铺nuclei_labels(blue_idx(is_light_blue=false) = 1;nuclei_labels = repmat(nuclei_labels,1 1 3); % 矩阵平铺blue_nuclei = he;blue_nuclei(nuclei_labels = 1) = 0;imshow(blue_nuclei), title(blue nuclei); % 显示处理后的图像【精品文档】第 页

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 试题/考题 > 初中试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号