图像纹理识别C#

Image Texture Recognition C#

我有一个处理疾病识别的项目。我们需要使用c#。我应该如何确定树是否被感染。我正在使用雅阁。成像我的相关值太高了。 这是示例图片 右侧: 已感染; 左侧: healthy/not 感染

既然你提到你正在使用Accord.NET,我相信你可能想看看the examples for Bag-of-Visual-Words。更具体地说,由于您提到了纹理识别,也许您应该考虑使用 Haralick 特征描述符从图像中提取纹理特征的 BoVW 示例。此示例转载如下:

// Ensure results are reproducible
Accord.Math.Random.Generator.Seed = 0;

// The Bag-of-Visual-Words model converts images of arbitrary 
// size into fixed-length feature vectors. In this example, we
// will be setting the codebook size to 3. This means all feature
// vectors that will be generated will have the same length of 3.

// By default, the BoW object will use the sparse SURF as the 
// feature extractor and K-means as the clustering algorithm.
// In this example, we will use the Haralick feature extractor.

// Create a new Bag-of-Visual-Words (BoW) model using Haralick features
var bow = BagOfVisualWords.Create(new Haralick()
{
    CellSize = 256, // divide images in cells of 256x256 pixels
    Mode = HaralickMode.AverageWithRange,
}, new KMeans(3));

// Generate some training images. Haralick is best for classifying
// textures, so we will be generating examples of wood and clouds:
var woodenGenerator = new WoodTexture();
var cloudsGenerator = new CloudsTexture();

Bitmap[] images = new[]
{
    woodenGenerator.Generate(512, 512).ToBitmap(),
    woodenGenerator.Generate(512, 512).ToBitmap(),
    woodenGenerator.Generate(512, 512).ToBitmap(),

    cloudsGenerator.Generate(512, 512).ToBitmap(),
    cloudsGenerator.Generate(512, 512).ToBitmap(),
    cloudsGenerator.Generate(512, 512).ToBitmap()
};

// Compute the model
bow.Learn(images);

bow.ParallelOptions.MaxDegreeOfParallelism = 1;

// After this point, we will be able to translate
// images into double[] feature vectors using
double[][] features = bow.Transform(images);

为了将此示例应用于您的问题,而不是使用 woodcloud 纹理生成器创建 images 变量,您可以从您自己的数据库中检索它们图片。稍后,在为数据集中的每个图像提取特征表示后,您可以使用这些表示来学习任何机器学习分类器,例如支持向量机,使用类似于以下代码:

// Now, the features can be used to train any classification
// algorithm as if they were the images themselves. For example,
// let's assume the first three images belong to a class and
// the second three to another class. We can train an SVM using

int[] labels = { -1, -1, -1, +1, +1, +1 };

// Create the SMO algorithm to learn a Linear kernel SVM
var teacher = new SequentialMinimalOptimization<Linear>()
{
    Complexity = 100 // make a hard margin SVM
};

// Obtain a learned machine
var svm = teacher.Learn(features, labels);

// Use the machine to classify the features
bool[] output = svm.Decide(features);

// Compute the error between the expected and predicted labels
double error = new ZeroOneLoss(labels).Loss(output); // should be 0

P.S.: 如果您考虑使用 ChiSquare kernel 而不是 Linear.

创建 SVM,则可能会在分类问题中获得更好的性能