Assignment 4 K-means algorithm

1. Apply K-means algorithm for image compression

Read a picture

Observe the image file size, memory size, image data structure, linearization

Use kmeans to cluster image pixel colors

Get the color category of each pixel, the color of each category

Compressed image generation: replace the original pixel color with clustering and return to two-dimensional

Observe the file size of compressed pictures, occupying memory size

 The source code is as follows:

 

The results are as follows:

 

2. Observe the problems that can be solved with K-means in learning and life.

Complete an application case from data-model training-test-prediction.

This case will be scored separately as one of the course outcomes.

 

Guess you like

Origin www.cnblogs.com/hqling/p/12714871.html