ΗΜΟΚΡΙΤΕΙΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΡΑΚΗΣ. Αναγνώριση Προτύπων. Ομαδοποίηση δεδομένων ΑΣΚΗΣΕΙΣ (K-means and ISODATA Clustering) Χριστόδουλος Χαμζάς

Σχετικά έγγραφα
1η εργασία για το μάθημα «Αναγνώριση προτύπων»

Αναγνώριση Προτύπων. Μη παραμετρικές τεχνικές Αριθμητικά. (Non Parametric Techniques)

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

Math 6 SL Probability Distributions Practice Test Mark Scheme

ΔΙΑΧΩΡΙΣΤΙΚΗ ΟΜΑΔΟΠΟΙΗΣΗ

Approximation of distance between locations on earth given by latitude and longitude

Instruction Execution Times

Assalamu `alaikum wr. wb.

2 Composition. Invertible Mappings

6.3 Forecasting ARMA processes

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

Numerical Analysis FMN011

Other Test Constructions: Likelihood Ratio & Bayes Tests

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

Second Order RLC Filters

Physical DB Design. B-Trees Index files can become quite large for large main files Indices on index files are possible.

Pg The perimeter is P = 3x The area of a triangle is. where b is the base, h is the height. In our case b = x, then the area is

ES440/ES911: CFD. Chapter 5. Solution of Linear Equation Systems

department listing department name αχχουντσ ϕανε βαλικτ δδσϕηασδδη σδηφγ ασκϕηλκ τεχηνιχαλ αλαν ϕουν διξ τεχηνιχαλ ϕοην µαριανι

EE512: Error Control Coding

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 5: Component Adaptation Environment (COPE)

ΕΙΣΑΓΩΓΗ ΣΤΗ ΣΤΑΤΙΣΤΙΚΗ ΑΝΑΛΥΣΗ

Reminders: linear functions

w o = R 1 p. (1) R = p =. = 1

Areas and Lengths in Polar Coordinates

Areas and Lengths in Polar Coordinates

Section 8.3 Trigonometric Equations

Queensland University of Technology Transport Data Analysis and Modeling Methodologies

Partial Differential Equations in Biology The boundary element method. March 26, 2013

CHAPTER 101 FOURIER SERIES FOR PERIODIC FUNCTIONS OF PERIOD

derivation of the Laplacian from rectangular to spherical coordinates

[1] P Q. Fig. 3.1

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

TMA4115 Matematikk 3

Bayesian statistics. DS GA 1002 Probability and Statistics for Data Science.

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

Inverse trigonometric functions & General Solution of Trigonometric Equations

The challenges of non-stable predicates

Μηχανική Μάθηση Hypothesis Testing

ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ

2. THEORY OF EQUATIONS. PREVIOUS EAMCET Bits.

Potential Dividers. 46 minutes. 46 marks. Page 1 of 11

5.4 The Poisson Distribution.

Notes on the Open Economy

ΗΜΥ 210 ΣΧΕΔΙΑΣΜΟΣ ΨΗΦΙΑΚΩΝ ΣΥΣΤΗΜΑΤΩΝ. Χειµερινό Εξάµηνο ΔΙΑΛΕΞΗ 3: Αλγοριθµική Ελαχιστοποίηση (Quine-McCluskey, tabular method)

Fractional Colorings and Zykov Products of graphs

Mean bond enthalpy Standard enthalpy of formation Bond N H N N N N H O O O

1. Ηλεκτρικό μαύρο κουτί: Αισθητήρας μετατόπισης με βάση τη χωρητικότητα

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

the total number of electrons passing through the lamp.

PARTIAL NOTES for 6.1 Trigonometric Identities

Spherical Coordinates

SCHOOL OF MATHEMATICAL SCIENCES G11LMA Linear Mathematics Examination Solutions

CRASH COURSE IN PRECALCULUS

HY380 Αλγόριθμοι και πολυπλοκότητα Hard Problems

Homework 3 Solutions

ΤΕΙ ΠΕΙΡΑΙΑ ΠΡΟΓΡΑΜΜΑ ΜΕΤΑΠΤΥΧΙΑΚΩΝ ΣΠΟΥΔΩΝ ΕΠΙΣΤΗΜΗ ΤΩΝ ΑΠΟΦΑΣΕΩΝ ΜΕ ΠΛΗΡΟΦΟΡΙΑΚΑ ΣΥΣΤΗΜΑΤΑ

4.6 Autoregressive Moving Average Model ARMA(1,1)

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

HISTOGRAMS AND PERCENTILES What is the 25 th percentile of a histogram? What is the 50 th percentile for the cigarette histogram?

Τελική Εξέταση =1 = 0. a b c. Τµήµα Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών. HMY 626 Επεξεργασία Εικόνας

Main source: "Discrete-time systems and computer control" by Α. ΣΚΟΔΡΑΣ ΨΗΦΙΑΚΟΣ ΕΛΕΓΧΟΣ ΔΙΑΛΕΞΗ 4 ΔΙΑΦΑΝΕΙΑ 1

Αποθήκες Δεδομένων και Εξόρυξη Δεδομένων:

The Simply Typed Lambda Calculus

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

Νευρωνικά ίκτυα και Εξελικτικός

1. Πόσοι αριθμοί μικρότεροι του διαιρούνται με όλους τους μονοψήφιους αριθμούς;

( ) 2 and compare to M.

Μορφοποίηση υπό όρους : Μορφή > Μορφοποίηση υπό όρους/γραμμές δεδομένων/μορφοποίηση μόο των κελιών που περιέχουν/

SCOPE OF ACCREDITATION TO ISO 17025:2005

Galatia SIL Keyboard Information

1 String with massive end-points

Review Test 3. MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

VBA Microsoft Excel. J. Comput. Chem. Jpn., Vol. 5, No. 1, pp (2006)

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 7η: Consumer Behavior Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Nov Journal of Zhengzhou University Engineering Science Vol. 36 No FCM. A doi /j. issn

Section 7.6 Double and Half Angle Formulas

Elements of Information Theory

Practice Exam 2. Conceptual Questions. 1. State a Basic identity and then verify it. (a) Identity: Solution: One identity is csc(θ) = 1

CHAPTER 48 APPLICATIONS OF MATRICES AND DETERMINANTS

Second Order Partial Differential Equations

- 1+x 2 - x 3 + 7x x x x x x 2 - x 3 - -

A Bonus-Malus System as a Markov Set-Chain. Małgorzata Niemiec Warsaw School of Economics Institute of Econometrics

1η προαιρετική εργαςία για το μάθημα «Αναγνώριςη προτύπων»

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

UDZ Swirl diffuser. Product facts. Quick-selection. Swirl diffuser UDZ. Product code example:

Homework 8 Model Solution Section

SOAP API. Table of Contents

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Section 9.2 Polar Equations and Graphs

Surface Mount Multilayer Chip Capacitors for Commodity Solutions

ΑΡΙΣΤΟΤΕΛΕΙΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΕΣΣΑΛΟΝΙΚΗΣ ΤΜΗΜΑ ΟΔΟΝΤΙΑΤΡΙΚΗΣ ΕΡΓΑΣΤΗΡΙΟ ΟΔΟΝΤΙΚΗΣ ΚΑΙ ΑΝΩΤΕΡΑΣ ΠΡΟΣΘΕΤΙΚΗΣ

Transcript:

Αναγνώριση Προτύπων Ομαδοποίηση δεδομένων ΑΣΚΗΣΕΙΣ (K-means and ISODATA Clustering) Χριστόδουλος Χαμζάς Τα περιεχόμενο αυτής της παρουσίασης βασίζεται στην παρουσίαση του αντίστοιχου διδακτέου μαθήματος του καθ. Kumar, University of Minessota. Βασίζεται στo Kef.8 &9 του βιβλίου: Introduction to Data Mining, Chpt 8, Pang-Ning Tan, Michael Steinbach, Vipin Kumar, Addison-Wesley, 2006 Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 1

Επιβλεπόμενη vs Μη-Επιβλεπόμενη Μάθηση Μέχρι τώρα θεωρήσαμε μεθόδους αναγνώρισης με classification όπου το πρότυπο χαρακτηρίζεται από τα μεγέθη {x,ω} Αυτά τα προβλήματα αναγνώρισης ονομάζονται Επιβλεπόμενα (supervised) αφού διατίθενται και το χαρακτηριστικό διάνυσμα και η σωστή απάντηση. Υπάρχουν όμως περιπτώσεις όπου δίνεται το χαρακτηριστικό διάνυσμα χωρίς την κλάση. Αυτές οι μέθοδοι καλούνται Μη-Επιβλεπόμενες (unsupervised) λόγω του ότι δεν χρησιμοποιούν τη σωστή απάντηση.

Επιβλεπόμενη vs Μη-Επιβλεπόμενη Μάθηση Αν και οι μέθοδοι μη επιβλεπόμενης μάθηση φαίνονται περιορισμένων δυνατοτήτων υπάρχουν πολλές περιπτώσεις που επιβάλλεται η χρήση τους: Ο χαρακτηρισμός πολλών δεδομένων μπορεί να αποβεί δαπανηρός (π.χ. αναγνώριση ομιλίας) Το είδος της κλάσης μπορεί να μην είναι γνωστό εξ αρχής.

Είδη αλγορίθμων ομαδοποίησης Ο K means και οι παραλλαγές του Παράγουν σετ ανεξάρτητων clusters Οι πιο γνωστοί είναι οι k-means και ISODATA Ιεραρχικοί αλγόριθμοι Το αποτέλεσμα είναι μια ιεραρχία εμφωλιασμένων clusters Χωρίζονται στους ενωτικούς (agglomerative) και διαχωριστικούς (divisive) Πυκνωτικοί αλγόριθμοι

K-means Clustering ΗΜΟΚΡΙΤΕΙΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΡΑΚΗΣ Αλγόριθμος διαχωρισμού Κάθε ομάδα συνδέεται με ένα centroid (κέντρο) Κάθε σημείο αποδίδεται στην ομάδα με το πιο κοντινό κέντρο Ο αριθμός των ομάδων, K, πρέπει να καθοριστεί Πολύ απλός αλγόριθμος

Αξιολόγηση των ομάδων του K means Η πιο κλασική μετρική είναι άθροισμα του τετραγώνου σφαλμάτων (Sum of Squared Error SSE) Για κάθε σημείο, το σφάλμα είναι η απόσταση από το κέντρο της κοντινότερης ομάδας Το SSE είναι το άθροισμα του τετραγώνου σφαλμάτων αυτών:. SSE K i 1 x C όπου x είναι ένα σημείο στην ομάδα C i και m i είναι το αντιπροσωπευτικό σημείο (το κέντρο) για την ομάδα C i εδομένων δυο ομάδων, μπορούμε να επιλέξουμε αυτήν με το μικρότερο σφάλμα Ένας εύκολος τρόπος για τη μείωση του SSE είναι η αύξηση του Κ, του αριθμού των ομάδων i dist ( m, x) Μια καλή ομαδοποίηση με μικρότερο Κ μπορεί να έχει μικρότερο SSE από μια κακή ομαδοποίηση με μεγαλύτερο Κ 2 i

K-means Το MatLab έχει μια δική του υλοποίηση του αλγορίθμου Kmeans. Για λεπτομέρειες χρησιμοποίησε το help kmeans Μία πιο απλή υλοποίηση είναι αυτή που δίνεται στο Πικράκη %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % FUNCTION [theta,bel,j]=k_means(x,theta) % This function implements the k-means algorithm, which requires % as input the number of clusters underlying the data set. The algorithm % starts with an initial estimation of the cluster representatives and % iteratively tries to move them into regions that are "dense" in data % vectors, so that a suitable cost function is minimized. This is % achieved by performing (usually) a few passes on the data set. The % algorithm terminates when the values of the cluster representatives % remain unaltered between two successive iterations. % % INPUT ARGUMENTS: % X: lxn matrix, each column of which corresponds to % an l-dimensional data vector. % theta: a matrix, whose columns contain the l-dimensional (mean) % representatives of the clusters. % % OUTPUT ARGUMENTS: % theta: a matrix, whose columns contain the final estimations of % the representatives of the clusters. % bel: N-dimensional vector, whose i-th element contains the % cluster label for the i-th data vector. % J: the value of the cost function (sum of squared Euclidean % distances of each data vector from its closest parameter % vector) that corresponds to the estimated clustering. % % (c) 2010 S. Theodoridis, A. Pikrakis, K. Koutroumbas, D. Cavouras %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [theta,bel,j]=k_means(x,theta) [l,n]=size(x); [l,m]=size(theta); e=1; iter=0; while(e~=0) iter=iter+1; theta_old=theta; dist_all=[]; for j=1:m dist=sum(((ones(n,1)*theta(:,j)'-x').^2)'); dist_all=[dist_all; dist]; end % dist_all Νxm έχει τις αποστάσεις των Ν σημειων από τα m κέντρα των clusters [q1,bel]=min(dist_all); J=sum(min(dist_all)); for j=1:m if(sum(bel==j)~=0) theta(:,j)=sum(x'.*((bel==j)'*ones(1,l))) / sum(bel==j); end end e=sum(sum(abs(theta-theta_old))); end Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 7

K-means clustering example

Παράδειγμα K-means % Example example_kmeans_isodata_cc % for data clustering C. Chamzas 15/6/2012 close('all'); clear; format compact ; % 1. To generate the first N1 points of X1, m=[1 1 ; 5 10 ; 10 4; 10 10]'; [l,c]=size(m); S1=[0.8 0.2; 0.2 0.1]; S2=[0.8 0.2; 0.2 0.8]; S3=[0.1 0.25; 0.25 0.8]; S4=[0.2 0.3; 0.3 0.8]; S(:,:,1)=S1; S(:,:,2)=S2; S(:,:,3)=S3; S(:,:,4)=S4; P=[1/4 1/4 1/4 1/4]; % 1. Generate X1 the data set N1=10000; randn('seed',0) [X1,y1]=generate_gauss_classes(m,S,P,N1); [l,n1]=size(x1); X1=4*X1; % Plot the data set figure(1), hold on plot(x1(1,:),x1(2,:),'.y') figure(1), axis equal % To apply the k-means algorithm for m = 4, work as in step 2 of Example 7.5.1. Pikrakis Attention data are given in rows m=4; [l,n]=size(x1); % places the initial centers randomly in the range of X1 theta_ini=rand(l,m); X1_max=max(X1'); X1_min=min(X1'); for j=1:l theta_ini(j,:)=theta_ini(j,:)*(x1_max(j)- X1_min(j))+X1_min(j); end [theta,bel,j]=k_means(x1,theta_ini); SSE_pikrakis=J theta k-means from Introduction to Pattern Recognition: A MATLAB Approach 50 45 40 35 30 25 20 The 4 centers 40.01 19.94 39.97 3.96 16.00 39.92 40.08 3.97 SSE = 180940 15 10 5 0-10 0 10 20 30 40 50 Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 9

.. %Matlab. Attention data are given in columns K=4; [IDX, C, SUMD] = kmeans(x1', K, 'Replicates',5); SSE_matlab=sum(SUMD) C=C' % plots the segmented data figure(3), hold on figure(3), plot(x1(1,idx==1),x1(2,idx==1),'r.',... X1(1,IDX==2),X1(2,IDX==2),'g*',X1(1,IDX==3),X1(2, IDX==3),'bo',... X1(1,IDX==4),X1(2,IDX==4),'cx',X1(1,IDX==5),X1(2, IDX==5),'md',... X1(1,IDX==6),X1(2,IDX==6),'yp',X1(1,IDX==7),X1(2, IDX==7),'ks') figure(3), plot(c(1,:),c(2,:),'ko','markerfacecolor','r') title('kmeans from Matlab'); figure(3), axis equal 50 45 40 35 30 25 20 15 10 5 0 kmeans from Matlab -10 0 10 20 30 40 50 17 iterations, total sum of distances = 180940 14 iterations, total sum of distances = 659350 4 iterations, total sum of distances = 180940 4 iterations, total sum of distances = 180940 4 iterations, total sum of distances = 180940 opts = statset('display','final'); [IDX, C, SUMD] = kmeans(x1', K, 'Replicates',5, 'Replicates',5, 'Options',opts); Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 10

ISODATA ISODATA είναι συντομογραφία του Iterative Self-Organizing Data Analysis Technique Algorithm Είναι επέκταση του k-means που εμπεριέχει ευριστικούς τρόπους για την αυτόματη επιλογή του πλήθους των κλάσεων Ο χρήστης επιλέγει τις παραμέτρους (Παράμετροι προγράμματος): NMIN_EX ελάχιστο πλήθος δειγμάτων ανά cluster ( OΝ ) ND επιθυμητό μέγιστο πλήθος cluster ( Κ ) σ S 2 μέγιστη διασπορά για διαχωρισμό clusters ( OS ) DMERGE μέγιστη απόσταση για ένωση clusters ( OC ) NMERGE μέγιστο πλήθος clusters που μπορούν να ενωθούν (L)

How ISODATA Works: 1. Cluster centers are randomly placed and pixels are assigned based on the shortest distance to center method 2. The standard deviation within each cluster, and the distance between cluster centers is calculated Clusters are split if one or more standard deviation is greater than the userdefined threshold Clusters are merged if the distance between them is less than the user-defined threshold 3. A second iteration is performed with the new cluster centers 4. Further iterations are performed until: the average inter-center distance falls below the user-defined threshold, the average change in the inter-center distance between iterations is less than a threshold, or the maximum number of iterations is reached Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 12

%ISODATA ON=15; % threshold number of elements for the elimination of a cluster. OC=5; % threshold distance for the union of clusters. OS=7; % deviation typical threshold for the division of a cluster. k=7; % number (maximum) cluster. L=2; % maximum number of clusters that can be mixed in a single iteration. I=10; % maximum number of iterations allowed. NO=1; % extra parameter to automatically answer no to the request of cambial any parameter. min_dist=50; % Minimum distance a point must be in each center. If you want to delete any point % Give a high value. %%%%%%%%%%%%%%%%%%%%% % Function ISODATA % %%%%%%%%%%%%%%%%%%%%% [C_ISO, Xcluster, A, clustering]=isodata_nd(x1', k, L, I, ON, OC, OS, NO, min_dist); C_ISO=C_ISO'; IDX_ISO=clustering'; % Evaluation the SSE error ISODATA [l,m]=size(c_iso); 50 dist_all=[]; 45 for j=1:m 40 dist=sum(((ones(n,1)*c_iso(:,j)'-x1').^2)'); 35 dist_all=[dist_all; dist]; 30 end 25 SSE_ISODATA=sum(min(dist_all)) 20 fprintf('number of Clusters: %d\n',a); C_ISO 15 10 5 0-10 0 10 20 30 40 50 Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 13

K-means Image Segmentation An image (I) Three-cluster image (J) on gray values of I Matlab code: I = double(imread( ')); Note that K-means result is noisy J = reshape(kmeans(i(:),3),size(i));

Παράδειγματα για Εικόνες % Example "example_kmeans_images_cc.m" % kmeans for image segnentation % C. Chamzas 15/6/2012 close('all'); clear; format compact ; Im = imread('trees.tif'); imshow(im); I = double(im); % segments it in 3 gray level colors [IDX, C, SUMD]=kmeans(I(:),3,'Replicates',5); J = reshape(idx,size(i)); mapgray=[c';c';c']'/max(i(:)); figure(2); imshow(j,mapgray); % segments it in 5 gray level colors [IDX, C, SUMD]=kmeans(I(:),5,'Replicates',5); J = reshape(idx,size(i)); mapgray=[c';c';c']'/max(i(:)); figure(3); imshow(j,mapgray); load mri I = D(:,:,8); figure(6); imshow(i,map); title('mri image_num = 8'); axis image MRI image num = 8 % segments it in 4 level colors I=double(I); [IDX, C, SUMD]=kmeans(I(:),4,'Start','uniform','Replicates',5,'EmptyAction','singleton'); J = reshape(idx,size(i)); maprgb=[ 1 0 0; 0 1 0; 0 0 1; 1 1 0; 1 0 1; 0 1 1]; mapgray=[c';c';c']'/max(i(:)); figure(7); imshow(j,maprgb); title('4 colors'); figure(8); imshow(j,mapgray);title('4 gray levels'); 4 gray levels 4 colors Τμήμα Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών 15