当前位置:网站首页>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');边栏推荐
- Excellent Kalman filter detailed article
- Understand chisel language. 23. Chisel sequential circuit (III) -- detailed explanation of chisel shift register
- 学习Typescript(一)
- File upload of native input tag
- 使用 Kmeans聚类实现颜色的分割
- npm常用命令
- Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children
- Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function
- WGAN、WGAN-GP、BigGAN
- 食品安全 | 菜板环境很重要,这些使用细节你知道吗?
猜你喜欢

Explain knative cloud function framework in simple terms!

vs2019社区版下载教程(详细)

WGAN、WGAN-GP、BigGAN

open3d库的安装,conda常用指令,导入open3d时报这个错误Solving environment: failed with initial frozen solve. Retrying w
![Text processing tool in shell, cut [option parameter] filename Description: the default separator is the built-in variable of tab, awk [option parameter] '/pattern1/{action1}filename and awk](/img/ed/941276a15d1c4ab67d397fb3286022.png)
Text processing tool in shell, cut [option parameter] filename Description: the default separator is the built-in variable of tab, awk [option parameter] '/pattern1/{action1}filename and awk

3D restoration paper: shape painting using 3D generative advantageous networks and recurrent revolutionary networks

Food safety | are you still eating fermented rice noodles? Be careful these foods are poisonous!

视觉SLAM十四讲笔记(一):第一讲+第二讲

pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0

Visual slam lecture notes (I): Lecture 1 + Lecture 2
随机推荐
Overview of PCL modules (1.6)
Understand chisel language. 23. Chisel sequential circuit (III) -- detailed explanation of chisel shift register
Stylegan paper notes + modify code to try 3D point cloud generation
Shell read read console input, use of read
After one year, the paper was finally accepted by the international summit
oracle rac 19c pdb实例当掉
Final examination paper of engineering materials
RobotFramework+Eclispe环境安装篇
Review summary of engineering surveying examination
Fsm onehot 答题记录
QT learning (II) -- a brief introduction to QT Creator
找工作 4 个月, 面试 15 家,拿到 3 个 offer
TFlite 的简单使用
并发之线程状态转换
面试必备:虾皮服务端15连问
二叉树习题总结
QT learning (II) -.Pro file explanation
使用 LSM-Tree 思想基于.NET 6.0 C# 写个 KV 数据库(案例版)
C # set different text watermarks for each page of word
Oracle RAC 19C PDB instance is down