图像纹理识别C#

时间:2017-09-29 04:26:10

标签: c# image-processing accord.net

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

1 个答案:

答案 0 :(得分:1)

由于您提到您使用的是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);

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

// 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而不是线性创建SVM,则可能会在分类问题中获得更好的性能。