Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 找出这两个图像之间的差异_Image_Image Processing_Jpeg_Python Imaging Library_Imaging - Fatal编程技术网

Image 找出这两个图像之间的差异

Image 找出这两个图像之间的差异,image,image-processing,jpeg,python-imaging-library,imaging,Image,Image Processing,Jpeg,Python Imaging Library,Imaging,在编程方面,我的代码检测两类图像之间的差异,总是拒绝一个类,而总是允许另一个 我还没有找到产生错误的图像和没有产生错误的图像之间的任何区别。但是必须有一些区别,因为产生错误的部分在100%的时间内都会产生错误,而其他部分则在100%的时间内按照预期工作 我特别检查了颜色格式:两组中的RGB;大小:无显著性差异;数据类型:两种类型均为uint8;像素值的大小:两者相似 下面是两个永远不起作用的图像,后面是两个始终起作用的图像: 这张图片永远不起作用: 这张图片永远不起作用: 此图像始终有效: 此

在编程方面,我的代码检测两类图像之间的差异,总是拒绝一个类,而总是允许另一个

我还没有找到产生错误的图像和没有产生错误的图像之间的任何区别。但是必须有一些区别,因为产生错误的部分在100%的时间内都会产生错误,而其他部分则在100%的时间内按照预期工作

我特别检查了颜色格式:两组中的RGB;大小:无显著性差异;数据类型:两种类型均为uint8;像素值的大小:两者相似

下面是两个永远不起作用的图像,后面是两个始终起作用的图像:

  • 这张图片永远不起作用:

  • 这张图片永远不起作用:

  • 此图像始终有效:

  • 此图像始终有效:

我怎样才能发现差异

场景是,我使用Firebase和Swift iOS前端将这些图像发送到托管在convnet上的Google Cloud ML引擎。有些图像一直在工作,而有些图像从来没有像上面那样工作过。此外,当我使用gcloud版本时,所有图像都可以工作。对我来说,这个问题必然存在于图像中。因此,我在这里发布的图像组。为确保完整性,请按要求提供代码

包含index.js文件的代码:

'use strict';

const functions = require('firebase-functions');
const gcs = require('@google-cloud/storage');
const admin = require('firebase-admin');
const exec = require('child_process').exec;
const path = require('path');
const fs = require('fs');
const google = require('googleapis');
const sizeOf = require('image-size');

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const rtdb = admin.database();
const dbRef = rtdb.ref();

function cmlePredict(b64img) {
    return new Promise((resolve, reject) => {
        google.auth.getApplicationDefault(function (err, authClient) {
            if (err) {
                reject(err);
            }
            if (authClient.createScopedRequired && authClient.createScopedRequired()) {
                authClient = authClient.createScoped([
                    'https://www.googleapis.com/auth/cloud-platform'
                ]);
            }

        var ml = google.ml({
           version: 'v1'
        });

        const params = {
            auth: authClient,
            name: 'projects/myproject-18865/models/my_model',
            resource: {
                instances: [
                {
                    "image_bytes": {
                    "b64": b64img
                    }
                }
                ]
            }
        };

        ml.projects.predict(params, (err, result) => {
            if (err) {
                reject(err);
            } else {
                resolve(result);
            }
        });
    });
});
}

function resizeImg(filepath) {
    return new Promise((resolve, reject) => {
        exec(`convert ${filepath} -resize 224x ${filepath}`, (err) => {
          if (err) {
            console.error('Failed to resize image', err);
            reject(err);
          } else {
            console.log('resized image successfully');
            resolve(filepath);
          }
        });
      });
}

exports.runPrediction = functions.storage.object().onChange((event) => {

    fs.rmdir('./tmp/', (err) => {
        if (err) {
            console.log('error deleting tmp/ dir');
        }
    });

const object = event.data;
const fileBucket = object.bucket;
const filePath = object.name;
const bucket = gcs().bucket(fileBucket);
const fileName = path.basename(filePath);
const file = bucket.file(filePath);

if (filePath.startsWith('images/')) {  
    const destination = '/tmp/' + fileName;
    console.log('got a new image', filePath);
    return file.download({
        destination: destination
    }).then(() => {
        if(sizeOf(destination).width > 224) {
            console.log('scaling image down...');
            return resizeImg(destination);
        } else {
            return destination;
        }
    }).then(() => {
        console.log('base64 encoding image...');
        let bitmap = fs.readFileSync(destination);
        return new Buffer(bitmap).toString('base64');
    }).then((b64string) => {
        console.log('sending image to CMLE...');
        return cmlePredict(b64string);
    }).then((result) => {
        console.log(`results just returned and is: ${result}`);  



        let predict_proba = result.predictions[0]

        const res_pred_val = Object.keys(predict_proba).map(k => predict_proba[k])
        const res_val = Object.keys(result).map(k => result[k])

        const class_proba = [1-res_pred_val,res_pred_val]
        const opera_proba_init = 1-res_pred_val
        const capitol_proba_init = res_pred_val-0

        // convert fraction double to percentage int
        let opera_proba = (Math.floor((opera_proba_init.toFixed(2))*100))|0
        let capitol_proba = (Math.floor((capitol_proba_init.toFixed(2))*100))|0
        let feature_list = ["houses", "trees"]


        let outlinedImgPath = '';
        let imageRef = db.collection('predicted_images').doc(filePath.slice(7));
               outlinedImgPath = `outlined_img/${filePath.slice(7)}`;
               imageRef.set({
                image_path: outlinedImgPath,
                opera_proba: opera_proba,
                capitol_proba: capitol_proba
            });

        let predRef = dbRef.child("prediction_categories");
        let arrayRef = dbRef.child("prediction_array");

    predRef.set({
            opera_proba: opera_proba,
            capitol_proba: capitol_proba,
            });

       arrayRef.set({first: {
           array_proba: [opera_proba,capitol_proba],
           brief_description: ["a","b"],
           more_details: ["aaaa","bbbb"],
           feature_list: feature_list},
        zummy1: "",
        zummy2: ""});

        return bucket.upload(destination, {destination: outlinedImgPath});

    });
} else {
    return 'not a new image';
}
}); 

问题是坏图像是灰度的,而不是我的模型所期望的RGB。我最初是通过观察形状来检查这一点的。但是“坏”图像有3个彩色通道,这3个通道中的每一个都存储了相同的数字——所以我的模型拒绝接受它们。此外,正如预期的,与我最初认为的相反,gcloud ML引擎predict CLI实际上也无法处理这些图像。我花了两天时间才弄明白

很明显,我给了你比你愿意接受的更多的智商,克里斯。更严重的是,我已经缩小了寻找上述解决方案的范围,我需要这里的帮助。除了我已经排除的属性之外,还有什么其他图像属性可以通过算法对这些图像进行分类的线索吗?谢谢好的,我现在就编辑代码。场景是,我使用firebase和swift iOS前端将这些图像发送到托管在convnet上的google cloud ML引擎。有些图像一直在工作,而有些图像从来没有像上面那样工作过。此外,当我使用gcloud版本时,所有图像都可以工作。对我来说,这个问题必然存在于图像中。我在这里发布给你们的是图像专家,他们在图像属性方面比我聪明得多,经验丰富得多。你们收到任何具体的错误消息吗?它会将输入调整到预期大小。我将尝试将一个“已拒绝”图像的大小更改为一个“已接受”图像的大小,并查看会发生什么。是的,这是错误:msg>TypeError:无法读取进程中未定义的file.download.then.then.then(/user\u code/index.js:128:51)的属性“0”。\u tickDomainCallback(internal/process/next\u tick.js:135:7)