图像识别中的K最近邻

发布于 2024-10-16 12:55:12 字数 533 浏览 0 评论 0原文

我目前正在研究项目或研究指南/教程。我必须确定三个叶子不同的物种,并且每个物种使用 100 个样本(具体来说是 300 个),我的教授要求我暗示 K-最近邻算法,使用在系统中上传的 100 个样本对系统中上传的图像进行分类。数据库作为参考。

我已经完成了系统的样本上传和图像处理,但我仍然需要应用 KNN 算法对它们进行分类,有什么建议或分步教程吗?

是否需要研究算法编码,或者是否有现有的库可以轻松地将KNN应用于C#语言的图像分类?每个叶种有 100 个图像样本就足够了吗?

更多信息:来自 martijin_himself 的回答

是的,我说的是树叶。嗯,问题是,唯一要考虑的特征是树叶的形状。忽略其他特征,例如颜色、尺寸等。而且我不完全知道何时或如何提取这些“特征向量”,将它们放在哪里以及如何将图像样本用作要分类的叶子的参考

关于系统的图像处理部分,图像经过二值化和斑点处理,使图像仅考虑其形状特征。因此,我上传到数据库中的所有样本也是如此。如果我缺少答案所需的信息,我深感抱歉。请耐心听我说。

提前致谢! :)

I am currently researching for projects or guide/tutorial for my research. I have to determine three leaf different species and is using 100 samples for each(300 just to be specific), my professor requires me to imply the K-Nearest Neighbor algorithm in classifying the uploaded image in the system using the 100 samples uploaded in the database as a reference.

I have done the uploading of the samples and image processing for the system, but I still have to apply the KNN algorithm in classifying them, any suggestions or step-by-step tutorials?

Is there a need to study in coding the algorithm or are there existing libraries for easily applying KNN in image classifying in C# language? and is having 100 image samples for each leaf specie enough?

more info.: a reply from martijin_himself's answer

Yes, I am talking about tree leaves. Well, a problem is, the only feature to consider is a tree leaf's shape. Neglecting other features such as color, size,..etc. And I don't exactly know when or how to extract these "Feature Vectors", where to put them and how the image samples will be used as a reference for the leaf to be classified

About the image processing part of the system, the image undergoes the process of binarization, and blobbing, having the image only consider it's shape only feature. So, same goes with all the samples I uploaded in the database. I am very sorry if I lack the information/s needed for the answers. Please bear with me.

Thanks in advance! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£噩梦荏苒 2024-10-23 12:55:12

如果我理解正确的话,您有一个包含 300 张图像的训练集,每个类别(或标签)100 张。

首先,您必须定义特征向量,这是您认为对图像分类很重要的一组图像特征或属性。如果您谈论的是(树)叶子,一个特征可能是图像中的颜色值?

第二步是定义一个距离函数来计算特征向量之间的距离。例如,具有大量红色的图像与具有大量绿色的图像之间的距离会更大。您甚至可以权衡这些特征以反映它们对距离的贡献的重要性。

接下来,您可以选择 k 值,并测试特征向量和距离函数的组合对训练集具有已知标签的图像进行分类的效果。这称为交叉验证。如果您的特征向量和距离函数表现不佳,则您可能选择了不代表该类的属性(例如图像的大小)。

在 C# 中实现此功能时,您可以为每个图像或类似的内容创建一个 FeatureVector 类,并且可能实现 IComparable(或类似)接口来计算到某些已知样本的距离函数。然后,您可以简单地创建一个列表并对其进行排序。这只是一个建议。

If I understand correctly, you have a training set of 300 images, 100 for each class (or label).

First, you have to define your feature vector, which is a set of image characteristics or attributes you think are important in classifying the images. If you are talking about (tree) leaves, one characteristic may be colour values in the image?

The second step would be to define a distance function that calculates the distance between feature vectors. An image with a lot of red would have a bigger distance to an image with a lot of green, for example. You could even weigh the features to reflect their importance in contribution to the distance.

Next, you can choose your value of k, and test how well the combination of your feature vector and distance function performs to classify the images with known labels for your training set. This is called cross-validation. If your feature vector and distance function does not perform well, you may have chosen attributes which are not representative for the class (such as size of the image).

When implementing this in c#, you could create a FeatureVector class for each image or something like that, and maybe implement the IComparable (or similar) interface to calculate the distance function to some known sample. You can then simply create a List and sort it. This is just a suggestion.

回忆凄美了谁 2024-10-23 12:55:12

结果,我将图像分为两部分(顶部和底部)。但我有三个特征向量(叶子的面积、顶部的面积和底部的面积)。与数据库中的所有样本相同。

因此,考虑到我拥有的三个特征向量,我通过计算它们的距离/s(欧几里德,w/c包含在K-NN算法中)并根据用户对它们进行分类,成功地将K-NN算法应用到我的研究中- K 的定义值。因此,结果以百分比形式表示。

谢谢大家的帮助^_^

As a result, I divided the image into two segments (top and bottom). But I had three feature vectors (Area of the leaf, area of it's top, and the area of it's bottom). Same with all the samples in the database.

So considering the three feature vectors that I have, I managed to apply the K-NN algorithm to my research by computing their distance/s (eauclidean, w/c is included in the K-NN algorithm) and classify them based on the user-defined value of K. So, the result had it in percentage.

Thanks for the help guys ^_^

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文