基于Android的纹理特征提取

基于Android的纹理特征提取,android,image-processing,feature-extraction,glcm,Android,Image Processing,Feature Extraction,Glcm,有人能帮我吗,如何在androd中用GLCM提取特征,我已经搜索过了,但没有找到,我只是在灰度scalenya上工作,因为我不知道如何用GLCM提取特征 public static Bitmap convertGrayscale(Bitmap src) { // constant factors final double GS_RED = 0.299; final double GS_GREEN = 0.587; final double GS_BLUE

有人能帮我吗,如何在androd中用GLCM提取特征,我已经搜索过了,但没有找到,我只是在灰度scalenya上工作,因为我不知道如何用GLCM提取特征

    public static Bitmap convertGrayscale(Bitmap src) {
    // constant factors
    final double GS_RED = 0.299;
    final double GS_GREEN = 0.587;
    final double GS_BLUE = 0.114;

    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    // pixel information
    int A, R, G, B;
    int pixel;

    // get image size
    int width = src.getWidth();
    int height = src.getHeight();

    // scan through every single pixel
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            // get one pixel color
            pixel = src.getPixel(x, y);
            // retrieve color of all channels
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            // take conversion up to one single value
            R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
            // set new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}
公共静态位图转换灰度(位图src){
//常数因子
最终双GS_红=0.299;
最终双GS_绿=0.587;
最终双GS_蓝=0.114;
//创建输出位图
位图bmOut=Bitmap.createBitmap(src.getWidth()、src.getHeight()、src.getConfig());
//像素信息
int A,R,G,B;
整数像素;
//获取图像大小
int width=src.getWidth();
int height=src.getHeight();
//扫描每一个像素
对于(int x=0;x
这是一个可以计算GLCM的类,它还可以为您提供14个Haralick特征(纹理特征)

现在要提取特征,您必须编写一个函数,在位图中获取图像,并在浮点数组中返回14个haralick特征。这就是这个函数

public void haralickFeatures(Bitmap b) throws IOException {
    glcm.haralickDist=1;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    b.compress(Bitmap.CompressFormat.PNG, 90, stream); // what 90 does ??
    GLCM.imageArray=new byte[]{};
    GLCM.imageArray = stream.toByteArray();
    glcm.process(b);
    glcm.data = new ArrayList<>(1);
    glcm.addData(glcm.features);
    List<double[]> featuresHar=glcm.getFeatures();

    for (double[] feature : featuresHar) {
        featureString=Arrays2.join(feature, ",", "%.5f");
    }
    String[] featureStr=featureString.split(Pattern.quote(","));
    float[] featureFlot = new float[featureStr.length];
    for (int i=0;i<featureStr.length;i++){
        featureFlot[i]=Float.parseFloat(featureStr[i]);
    }
    //featureFlot is array that contain all 14 haralick features

}
public void-haralickFeatures(位图b)引发IOException{
glcm.haralickDist=1;
ByteArrayOutputStream=新建ByteArrayOutputStream();
b、 压缩(Bitmap.CompressFormat.PNG,90,stream);//90的作用是什么??
GLCM.imageArray=新字节[]{};
GLCM.imageArray=stream.toByteArray();
glcm.过程(b);
glcm.data=新阵列列表(1);
glcm.addData(glcm.features);
List featuresHar=glcm.getFeatures();
for(双[]功能:featuresHar){
featureString=Arrays2.join(feature,“,”,“%.5f”);
}
String[]featureStr=featureString.split(Pattern.quote(“,”);
float[]featureFlot=新的float[featureStr.length];

对于(int i=0;i什么是Arrays2?为此干杯!作为对使用此代码感兴趣的任何人的旁注,您将需要使用Matrix类和Arrays2类的“gradle implementation'de.lmu.ifi.dbs.utilities:common extension lib:2.6.0”。
GLCM glcm=new GLCM();
public void haralickFeatures(Bitmap b) throws IOException {
    glcm.haralickDist=1;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    b.compress(Bitmap.CompressFormat.PNG, 90, stream); // what 90 does ??
    GLCM.imageArray=new byte[]{};
    GLCM.imageArray = stream.toByteArray();
    glcm.process(b);
    glcm.data = new ArrayList<>(1);
    glcm.addData(glcm.features);
    List<double[]> featuresHar=glcm.getFeatures();

    for (double[] feature : featuresHar) {
        featureString=Arrays2.join(feature, ",", "%.5f");
    }
    String[] featureStr=featureString.split(Pattern.quote(","));
    float[] featureFlot = new float[featureStr.length];
    for (int i=0;i<featureStr.length;i++){
        featureFlot[i]=Float.parseFloat(featureStr[i]);
    }
    //featureFlot is array that contain all 14 haralick features

}