2017-09-29 218 views
1

我有一个处理疾病识别的项目。我们被要求使用c#。我应该如何确定树是否受到感染。我正在使用雅阁。成像我的相关值太高。 这里是一个样本图片 右侧:感染; 左侧:健康/未感染图像纹理识别C#

回答

0

既然你提到你正在使用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 

PS :如果考虑使用ChiSquare kernel而不是Linear来创建SVM,可能会在分类问题中获得更好的性能。