File Exchange

image thumbnail

K-Nearest Neighbors for image segmentation

version 1.3.0.0 (1.13 KB) by Makrim

Makrim (view profile)

Implementation of the algorithm K-Nearest Neighbors.

13 Downloads

Updated 22 Apr 2014

View License

Script Exemple :
-------------
% k of k-nearest neighbors
k = 3 ;
% generate a test image data , a matrix of 3 by 3, values are doubles that
% range from 10 to 20
im_test_data = [10 20 30; 20 10 30; 20 10 30];

% generate a training/apprentissage data image from test data image
im_tr_data = [10 0 30;0 10 0; 20 0 30];

% generate a truth image labels with 3 by 3 matrix, values are integers
% that range from 1 to 3 (10 correspond to label 1, 20 to 2 and 30 to 3)
im_t_lbls = [1 2 3; 2 1 3; 2 1 3];

% generate a training/apprentissage image labels from truth image labels
im_tr_lbls = [1 0 3;0 1 0; 2 0 3];

% we are looking for "test_lbls" ?
test_lbls = knnAlgo(im_test_data, im_tr_data,im_tr_lbls,k);

Comments and Ratings (5)

Makrim

Makrim (view profile)

sorry but I have not edited this code since 2014 feel free to costumize it for your needs ...

sir,
i am having four standard deviated value of images.How do i form a matrix using KNN classifier?so that i can assign a the value corresponds to the image

Merin George

Sir i need 2D image segmentation algorithm. can u pls help me?

Sir i need to segment an image not its features value. how can i modify it for image segment.

Makrim

Makrim (view profile)

Feel free to criticize the algorithm in order to improve it please.

Updates

1.3.0.0

update

1.2.0.0

improved the description

1.1.0.0

problem solved of frequency when there is unique knn

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor