生成和使用许多图像失败

时间:2014-07-25 01:31:26

标签: image opencv

我在尝试操作大量图片时遇到问题。如果这个数字很低,我可以运行算法,但是当我使用大量图像运行它时,它不起作用。

所以,我有12个图像,我需要从这些图像中再生成288个图像。我可以从第一个图像生成第一组288个图像,从第二个图像生成第二个图像。但之后,程序停止,然后我收到以下错误:

" mm_areaopen:lib失败"

以下是算法停止的代码:

for (int n = 0; n < 3; n++){

    // tecido Normal -------------------------------------------------------------------------------------|

    str_normal.str("");
    title_normal.clear();
    str_normal << "normal-" << n + 1 << ".tif";
    title_normal = str_normal.str();
    normal = title_normal.c_str();

    original_normal = cvLoadImage(normal, CV_LOAD_IMAGE_GRAYSCALE);

    image_names[i] = normal;

    str_normal.str("");
    title_normal.clear();
    str_normal << "normal-" << n + 1 << "-selection" << ".tif";
    title_normal = str_normal.str();
    normal = title_normal.c_str();

    goldStandard_normal = imread(normal, IMREAD_UNCHANGED);

    // tecido NIC-1 -------------------------------------------------------------------------------------|

    str_nic1.str("");
    title_nic1.clear();
    str_nic1 << "nic1-" << n + 1 << ".tif";
    title_nic1 = str_nic1.str();
    nic1 = title_nic1.c_str();

    original_nic1 = cvLoadImage(nic1, CV_LOAD_IMAGE_GRAYSCALE);

    image_names[i] = nic1;

    str_nic1.str("");
    title_nic1.clear();
    str_nic1 << "nic1-" << n + 1 << "-selection" << ".tif";
    title_nic1 = str_nic1.str();
    nic1 = title_nic1.c_str();

    goldStandard_nic1 = imread(nic1, IMREAD_UNCHANGED);

    // tecido NIC-2 -------------------------------------------------------------------------------------|

    str_nic2.str("");
    title_nic2.clear();
    str_nic2 << "nic2-" << n + 1 << ".tif";
    title_nic2 = str_nic2.str();
    nic2 = title_nic2.c_str();

    original_nic2 = cvLoadImage(nic2, CV_LOAD_IMAGE_GRAYSCALE);

    image_names[i] = nic2;

    str_nic2.str("");
    title_nic2.clear();
    str_nic2 << "nic2-" << n + 1 << "-selection" << ".tif";
    title_nic2 = str_nic2.str();
    nic2 = title_nic2.c_str();

    goldStandard_nic2 = imread(nic2, IMREAD_UNCHANGED);

    // tecido NIC-3 -------------------------------------------------------------------------------------|

    str_nic3.str("");
    title_nic3.clear();
    str_nic3 << "nic3-" << n + 1 << ".tif";
    title_nic3 = str_nic3.str();
    nic3 = title_nic3.c_str();

    original_nic3 = cvLoadImage(nic3, CV_LOAD_IMAGE_GRAYSCALE);

    image_names[i] = nic3;

    str_nic3.str("");
    title_nic3.clear();
    str_nic3 << "nic3-" << n + 1 << "-selection" << ".tif";
    title_nic3 = str_nic3.str();
    nic3 = title_nic3.c_str();

    goldStandard_nic3 = imread(nic3, IMREAD_UNCHANGED);

    for (i = 0; i < 12; i++){

        j = 0;

        // tecido Normal -------------------------------------------------------------------------------------|

        if (i >= 0 && i < 3){

            for (p1 = 18; p1 <= 23; p1++){
                for (p2 = 1; p2 <= 3; p2++){
                    for (p3 = 1; p3 <= 4; p3++){
                        for (p4 = 100; p4 <= 175; p4 = p4 + 25){

                            parameterSet[j].p1 = p1;
                            parameterSet[j].p2 = p2;
                            parameterSet[j].p3 = p3;
                            parameterSet[j].p4 = p4;

                            parameterSet[j].media = 0;

                            j++;

                            watershedImage_normal = Morphology::doPipeline(original_normal, p1, p2, p3, p4);
                            img_normal = watershedImage_normal;

                            cv::floodFill(img_normal, cvPoint(50, 50), cvScalar(255, 255, 255));
                            bitwise_not(img_normal, img_normal);

                            str_normal.str("");
                            title_normal.clear();
                            str_normal << "normal-" << n + 1 << "-" << p1 << "-" << p2 << "-" << p3 << "-" << p4 << ".tif";
                            title_normal = str_normal.str();

                            imwrite(title_normal, img_normal);

                            input_normal = imread(title_normal, IMREAD_UNCHANGED);

                            parameterSet[j].overlap[i] = caib::areaOverlap(goldStandard_normal, input_normal);

                        }
                    }
                }
            }
        }

        // tecido NIC-1 -------------------------------------------------------------------------------------|

        if (i >= 3 && i < 6){

            for (p1 = 18; p1 <= 23; p1++){
                for (p2 = 1; p2 <= 3; p2++){
                    for (p3 = 1; p3 <= 4; p3++){
                        for (p4 = 100; p4 <= 175; p4 = p4 + 25){

                            watershedImage_nic1 = Morphology::doPipeline(original_nic1, p1, p2, p3, p4);
                            img_nic1 = watershedImage_nic1;

                            cv::floodFill(img_nic1, cvPoint(50, 50), cvScalar(255, 255, 255));
                            bitwise_not(img_nic1, img_nic1);

                            str_nic1.str("");
                            title_nic1.clear();
                            str_nic1 << "nic1-" << n + 1 << "-" << p1 << "-" << p2 << "-" << p3 << "-" << p4 << ".tif";
                            title_nic1 = str_nic1.str();

                            imwrite(title_nic1, img_nic1);

                            input_nic1 = imread(title_nic1, IMREAD_UNCHANGED);

                            parameterSet[j].overlap[i] = caib::areaOverlap(goldStandard_nic1, input_nic1);

                        }
                    }
                }
            }

        }

        // tecido NIC-2 -------------------------------------------------------------------------------------|

        if (i >= 6 && i < 9){

            for (p1 = 18; p1 <= 23; p1++){
                for (p2 = 1; p2 <= 3; p2++){
                    for (p3 = 1; p3 <= 4; p3++){
                        for (p4 = 100; p4 <= 175; p4 = p4 + 25){

                            watershedImage_nic2 = Morphology::doPipeline(original_nic2, p1, p2, p3, p4);
                            img_nic2 = watershedImage_nic2;

                            cv::floodFill(img_nic2, cvPoint(50, 50), cvScalar(255, 255, 255));
                            bitwise_not(img_nic2, img_nic2);

                            str_nic2.str("");
                            title_nic2.clear();
                            str_nic2 << "nic2-" << n + 1 << "-" << p1 << "-" << p2 << "-" << p3 << "-" << p4 << ".tif";
                            title_nic2 = str_nic2.str();

                            imwrite(title_nic2, img_nic2);

                            input_nic2 = imread(title_nic2, IMREAD_UNCHANGED);

                            parameterSet[j].overlap[i] = caib::areaOverlap(goldStandard_nic2, input_nic2);

                        }
                    }
                }
            }
        }

        // tecido NIC-3 -------------------------------------------------------------------------------------|

        if (i >= 9 && i < 12){

            for (p1 = 18; p1 <= 23; p1++){
                for (p2 = 1; p2 <= 3; p2++){
                    for (p3 = 1; p3 <= 4; p3++){
                        for (p4 = 100; p4 <= 175; p4 = p4 + 25){

                            watershedImage_nic3 = Morphology::doPipeline(original_nic3, p1, p2, p3, p4);
                            img_nic3 = watershedImage_nic3;

                            cv::floodFill(img_nic3, cvPoint(80, 80), cvScalar(255, 255, 255));
                            bitwise_not(img_nic3, img_nic3);

                            str_nic3.str("");
                            title_nic3.clear();
                            str_nic3 << "nic3-" << n + 1 << "-" << p1 << "-" << p2 << "-" << p3 << "-" << p4 << ".tif";
                            title_nic3 = str_nic3.str();

                            imwrite(title_nic3, img_nic3);

                            input_nic3 = imread(title_nic3, IMREAD_UNCHANGED);

                            parameterSet[j].overlap[i] = caib::areaOverlap(goldStandard_nic3, input_nic3);

                        }
                    }
                }
            }
        }
    }

打开所有&#34; nic1-1.tif&#34;图像,出现错误。有谁知道为什么会这样?

顺便说一下,Morphology :: doPipeline方法使用SDC形态工具箱来实现C ++ 1.6。

抱歉我的英文。

1 个答案:

答案 0 :(得分:0)

您可以像下面一样包装旧版库。请注意,您创建了一个IplImage,然后传递了需要IplImage *的函数的地址

 cv::Mat myPipeline(cv::Mat original_nic, int p1, int p2, int p3, int p4)
 { 
     IplImage original_iplimage = IplImage(original_nic);
     IplImage* watershedImage = Morphology::doPipeline( & original_iplimage , p1, p2, p3, p4);
     cv::Mat result(watershedImage, true);
     cvReleaseImage(watershedImage);
     return result;
 }