K-means Clustering for Image Segmentation

 
ECE
 
596
 
HW 2 Notes
 
1
 
K-means clustering
 
2
 
Pixel-wise image segmentation in RGB color space.
 
K-means clustering
 
3
1.
Make a copy of your
original image.
 
K-means clustering
 
4
1.
Make a copy of your
original image.
Copying input image to
a buffer image.
 
K-means clustering
 
5
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
centers[ i ][ j ]:
,where i = 1 … number of clusters
 j = 1 … 3 (R,G,B  channels)
 
K-means clustering
 
6
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
centers[ i ][ j ]:
,where i = 1 … number of clusters
 j = 1 … 3 (R,G,B  channels)
Task 1 : random seeds
Task 2: pixel seeds
Task 3: histogram seeds
 
K-means clustering
 
7
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
Cluster
centers
 
K-means clustering
 
8
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
Cluster
centers
L1
distance
 
K-means clustering
 
9
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
Cluster
centers
L1
distance
smallest
 
K-means clustering
 
10
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
Cluster
centers
 
K-means clustering
 
11
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
Cluster
centers
 
K-means clustering
 
12
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
 
K-means clustering
 
13
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
Take the mean and
update cluster
center color.
 
K-means clustering
 
14
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
Do the
same for
all cluster
centers.
 
K-means clustering
 
15
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
5.
Check
convergence.
Exit Looping
, if …
sum of the L1 distances between the new
cluster centers and the previous cluster centers
is less than epsilon*num_clusters.
 
K-means clustering
 
16
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
5.
Check
convergence.
Otherwise
Loop for a max of
100 iterations.
 
K-means clustering
 
17
1.
Make a copy of your
original image.
2.
Initialize cluster centers.
double
**
 
centers
3.
Find closest cluster for
each pixel.
|Rp-Rc|+|Gp-Gc|+|Bp-Bc|
4.
Update cluster centers.
5.
Check
convergence.
6.
Render
result.
Assign pixel color with the
cluster center color it
belongs to.
 
Task 1. With Random Seeds
 
void RandomSeedImage(double **image, int num_clusters)
 
Choose a random number!
Range of values:     
0 ~ 255
What you can do:   
rand()
 
%
 
256
Set epsilon = 30 (fine tune as necessary)
 
18
2.
Initialize cluster centers.
double
**
 
centers
centers[ i ][ j ]:
,where i = 1 … number of clusters
 j = 1 … 3 (R,G,B  channels)
10/15 – 10/20
 
Task 2. With Pixel Seeds
 
void PixelSeedImage(double **image, int num_clusters)
 
Choose a random pixel from image!
Range of values:
          column = 0 ~ (imageWidth – 1)
          row = 0 ~ (imageHeight – 1)
What you can use:  
rand() % something…
Set epsilon = 30.
 
19
2.
Initialize cluster centers.
double
**
 
centers
centers[ i ][ j ]:
,where i = 1 … number of clusters
 j = 1 … 3 (R,G,B  channels)
10/21 – 10/24
 
Task 2. With Pixel Seeds
 
void PixelSeedImage(double **image, int num_clusters)
 
Choose a random pixel from image!
Range of values:
          column = 0 ~ (imageWidth – 1)
          row = 0 ~ (imageHeight – 1)
What you can use:  
rand() % something…
Set epsilon = 30.
 
20
2.
Initialize cluster centers.
double
**
 
centers
centers[ i ][ j ]:
,where i = 1 … number of clusters
 j = 1 … 3 (R,G,B  channels)
Choose a pixel and make its
RGB values a seed if it is
sufficiently different (dist(L1)
>= 100) from already-
selected seeds!
10/21 – 10/24
 
Task 3. With Histogram Seeds
 
void HistogramSeedImage(double** image, int num_clusters)
 
 
 
 
 
 
 
Set epsilon = anything.
 
 
21
2.
Initialize cluster centers.
double
**
 
centers
Extra Credit
Slide Note
Embed
Share

Dive into the world of K-means clustering for pixel-wise image segmentation in the RGB color space. Learn the steps involved, from making copies of the original image to initializing cluster centers and finding the closest cluster for each pixel based on color distances. Explore different seeding methods and cluster center initialization techniques to enhance your image segmentation process.

  • Image Segmentation
  • K-means Clustering
  • RGB Color Space
  • Pixel-wise
  • Cluster Centers

Uploaded on Sep 21, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. ECE 596 HW 2 Notes 1

  2. K-means clustering Pixel-wise image segmentation in RGB color space. 2

  3. K-means clustering 1. Make a copy of your original image. 3

  4. K-means clustering 1. Make a copy of your original image. Copying input image to a buffer image. 4

  5. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers centers[ i ][ j ]: ,where i = 1 number of clusters j = 1 3 (R,G,B channels) 5

  6. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers centers[ i ][ j ]: ,where i = 1 number of clusters j = 1 3 (R,G,B channels) Task 1 : random seeds Task 2: pixel seeds Task 3: histogram seeds 6

  7. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Cluster centers 7

  8. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers L1 3. distance Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Cluster centers 8

  9. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers L1 3. distance Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Cluster centers 9

  10. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Cluster centers 10

  11. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Cluster centers 11

  12. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| 4. Update cluster centers. 12

  13. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Take the mean and update cluster center color. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| 4. Update cluster centers. 13

  14. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Do the same for all cluster centers. 4. Update cluster centers. 14

  15. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Exit Looping, if sum of the L1 distances between the new cluster centers and the previous cluster centers is less than epsilon*num_clusters. 5. 4. Check Update cluster centers. convergence. 15

  16. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Otherwise Loop for a max of 100 iterations. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| 5. 4. Check Update cluster centers. convergence. 16

  17. K-means clustering 1. 2. Make a copy of your original image. Initialize cluster centers. double**centers 3. Find closest cluster for each pixel. |Rp-Rc|+|Gp-Gc|+|Bp-Bc| Assign pixel color with the cluster center color it belongs to. 6. 5. 4. Render result. Check Update cluster centers. convergence. 17

  18. 10/15 10/20 Task 1. With Random Seeds 2. Initialize cluster centers. double**centers void RandomSeedImage(double **image, int num_clusters) Choose a random number! Range of values: 0 ~ 255 What you can do: rand() % 256 Set epsilon = 30 (fine tune as necessary) centers[ i ][ j ]: ,where i = 1 number of clusters j = 1 3 (R,G,B channels) 18

  19. 10/21 10/24 Task 2. With Pixel Seeds 2. Initialize cluster centers. double**centers void PixelSeedImage(double **image, int num_clusters) Choose a random pixel from image! Range of values: column = 0 ~ (imageWidth 1) row = 0 ~ (imageHeight 1) What you can use: rand() % something Set epsilon = 30. centers[ i ][ j ]: ,where i = 1 number of clusters j = 1 3 (R,G,B channels) 19

  20. 10/21 10/24 Task 2. With Pixel Seeds Choose a pixel and make its RGB values a seed if it is sufficiently different (dist(L1) >= 100) from already- selected seeds! 2. Initialize cluster centers. double**centers void PixelSeedImage(double **image, int num_clusters) Choose a random pixel from image! Range of values: column = 0 ~ (imageWidth 1) row = 0 ~ (imageHeight 1) What you can use: rand() % something Set epsilon = 30. centers[ i ][ j ]: ,where i = 1 number of clusters j = 1 3 (R,G,B channels) 20

  21. Extra Credit Task 3. With Histogram Seeds 2. Initialize cluster centers. double**centers void HistogramSeedImage(double** image, int num_clusters) Number of pixels Histogram: (color or gray) histWidth Set epsilon = anything. 21 histBins

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#