【发布时间】:2015-05-12 08:07:38
【问题描述】:
我已经使用上面的代码进行图像分割和提取,但是我们如何使用 knn 进行分类呢?我需要代码方面的帮助。我已经在 mathworks 中搜索了 knn 分类,但我无法理解语法。任何有关代码的帮助将不胜感激。
执行后得到如下结果:
如果我是正确的,我的目标是在使用 knn 分类后预测 matlab 编译器或记事本中的字符,但我无法在上述代码之后编写 k 最近邻。
%% Image segmentation and extraction
%% Read Image
imagen=imread('C:\Documents and Settings\vijaykumar\Desktop\v.jpg');
%% Show image
figure(1)
imshow(imagen);
title('INPUT IMAGE WITH NOISE')
%% Convert to gray scale
if size(imagen,3)==3 % RGB image
imagen=rgb2gray(imagen);
end
%% Convert to binary image
threshold = graythresh(imagen);
imagen =~im2bw(imagen,threshold);
%% Remove all object containing fewer than 30 pixels
imagen = bwareaopen(imagen,30);
pause(1)
%% Show image binary image
figure(2)
imshow(~imagen);
title('INPUT IMAGE WITHOUT NOISE')
%% Label connected components
[L Ne]=bwlabel(imagen);
%% Measure properties of image regions
propied=regionprops(L,'BoundingBox');
hold on
%% Plot Bounding Box
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
pause (1)
%% Objects extraction
figure
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
imshow(~n1);
pause(0.5)
end
【问题讨论】:
-
k 最近邻是一种有监督的机器学习算法,这意味着您需要一个训练数据集来学习。你有吗?
-
一些cmets:(1)这段代码根本没有做KNN。您所做的只是提取对象 (2) 如果您想使用 KNN,您需要有一组地面实况数据或一些您想要比较查询的数据以匹配字符。 (3) 你在这里比较的数据到底是什么?你的数据是像素吗?您从像素中提取的特征?一些描述如何定义每个字符的形状的参数,比如弧?界?在您提供有关数据的更多见解之前,无法回答您的问题。
标签: matlab image-processing classification nearest-neighbor knn