当前位置:网站首页>Color segmentation using kmeans clustering
Color segmentation using kmeans clustering
2022-07-27 10:12:00 【User 9925864】
I shared before kmeans Algorithm ( Portal : Data mining algorithms —K-Means Algorithm ), In this issue, let's share Kmeans Clustering realizes color segmentation , Use L*a*b* Sum of color Spaces K Mean clustering automatic color segmentation .
step 1: Read images
Read hestain.png,
he = imread('hestain.png');
imshow(he), title('H&E image');step 2: Take the image from RGB The color space is converted to L*a*b* Color space
L*a*b* Color space ( Also known as CIELAB or CIE L*a*b*) Be able to quantify visual differences .
L*a*b* The color space is from CIE XYZ Trichromatic value derived .L*a*b* Space contains photometric layers 'L*'、 Chrominance layer 'a*'( Indicates that the color falls along the red - The position of the green axis ) And chroma layer 'b*'( Indicates that the color falls along the blue - The position of the Yellow axis ). All color information is 'a*' and 'b*' layer . Euclidean distance measurement can be used to measure the difference between two colors .
Use rgb2lab Convert image to L*a*b* Color space .
lab_he = rgb2lab(he);step 3: use K Mean clustering pairs are based on 'a*b*' Space color classification
Clustering is a method of separating groups of objects .K Mean clustering treats each object as having a position in space . It divides objects into partitions , Make the objects in each cluster as close to each other as possible , And as far away from objects in other clusters as possible .K Mean clustering requires you to specify the number of clusters to divide and the distance metric used to quantify the distance between two objects .
Because the color information is based on 'a*b*' Color space , So your object has 'a*' and 'b*' Value in pixels . Convert data to data type single, So as to meet with imsegkmeans Use a combination of . Use imsegkmeans Cluster objects into three clusters .
ab = lab_he(:,:,2:3);
ab = im2single(ab);
nColors = 3;
% Repeat clustering three times , Avoid local optimizations
pixel_labels = imsegkmeans(ab,nColors,'NumAttempts',3);For each object in the input ,imsegkmeans An index or label corresponding to the cluster will be returned . Label each pixel in the image with the label of the pixel .
imshow(pixel_labels,[])
title('Image Labeled by Cluster Index');step 4: Create a color split H&E The image of the image
Use pixel_labels, Can be separated by color hestain.png Objects in the , This will produce three images .
mask1 = pixel_labels==1;
cluster1 = he .* uint8(mask1);
imshow(cluster1)
title('Objects in Cluster 1');mask2 = pixel_labels==2;
cluster2 = he .* uint8(mask2);
imshow(cluster2)
title('Objects in Cluster 2');mask3 = pixel_labels==3;
cluster3 = he .* uint8(mask3);
imshow(cluster3)
title('Objects in Cluster 3');step 5: Split core
cluster 3 Contains blue objects . Please note that , There are dark blue and light blue objects . You can use L*a*b* In color space 'L*' Layer to separate dark blue and light blue . The nucleus is dark blue .
As mentioned earlier ,'L*' The layer contains the brightness value of each color . Extract the brightness value of pixels in this cluster , And use imbinarize Set the threshold with the global threshold . A mask is_light_blue Gives the index of light blue pixels .
L = lab_he(:,:,1);
L_blue = L .* double(mask3);
L_blue = rescale(L_blue);
idx_light_blue = imbinarize(nonzeros(L_blue));Copy the mask of the blue object mask3, Then remove the light blue pixels from the mask . Apply the new mask to the original image and display the result . Only dark blue nuclei are visible .
blue_idx = find(mask3);
mask_dark_blue = mask3;
mask_dark_blue(blue_idx(idx_light_blue)) = 0;
blue_nuclei = he .* uint8(mask_dark_blue);
imshow(blue_nuclei)
title('Blue Nuclei');边栏推荐
- 3D face reconstruction and dense alignment with position map progression network
- Cannot start after installing MySQL 5.7.27 in CentOS 7? (Language bash)
- pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0
- Expose a technology boss from a poor family
- Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
- 华为交换机双上行组网Smart-link配置指南
- Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
- Practice and exploration of overseas site Seata of ant group
- VS2019+CUDA11.1新建项目里没有CUDA选项
- WGAN、WGAN-GP、BigGAN
猜你喜欢

Visual slam lecture notes (I): Lecture 1 + Lecture 2

GBase 8a MPP集群扩容实战

Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)

Concurrent thread state transition

3D face reconstruction and dense alignment with position map progression network

Uninstall cuda11.1

吃透Chisel语言.22.Chisel时序电路(二)——Chisel计数器(Counter)详解:计数器、定时器和脉宽调制

数据库性能系列之子查询
[email protected]、$?、env看所有的全局变量值、set看所有变量"/>Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量

Interview JD T5, was pressed on the ground friction, who knows what I experienced?
随机推荐
Shell operator, $((expression)) "or" $[expression], expr method, condition judgment, test condition, [condition], comparison between two integers, judgment according to file permission, judgment accor
PCL各模块概述(1.6)
Summary of engineering material knowledge points (full)
蚂蚁集团境外站点 Seata 实践与探索
SE(Squeeze and Excitation)模块的理解以及代码实现
pytorch的安装(非常详细)
历时一年,论文终于被国际顶会接收了
Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)
VS2019+CUDA11.1新建项目里没有CUDA选项
StyleGAN论文笔记+修改代码尝试3D点云生成
Understand chisel language. 22. Chisel sequential circuit (II) -- detailed explanation of chisel counter: counter, timer and pulse width modulation
Snowflake vs. Databricks谁更胜一筹?2022年最新战报
Brush the title "sword finger offer" day04
How does data analysis solve business problems? Here is a super detailed introduction
Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
省应急管理厅:广州可争取推广幼儿应急安全宣教经验
面试京东 T5,被按在地上摩擦,鬼知道我经历了什么?
Robotframework+eclispe environment installation
数据库性能系列之子查询
Intermediate and advanced test questions ": what is the implementation principle of mvcc?