当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryImage::Otsu方法代码示例

本文整理汇总了C++中BinaryImage::Otsu方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryImage::Otsu方法的具体用法?C++ BinaryImage::Otsu怎么用?C++ BinaryImage::Otsu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryImage的用法示例。


在下文中一共展示了BinaryImage::Otsu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    PngImage Png;
    Png.Read("./cballs.png");

    GrayImage GrayOriginal, GrayBlured, GrayAdjusted;
    // Convert original PNG to gray-level image
    GrayOriginal.Convert(Png);

    // Blur PNG image
    FastGaussianBlur::Blur<3>(Png, 4.0);
    Png.Write("./cballs_blured.png");
    
    // Convert Blured PNG image to gray-level image
    GrayBlured.Convert(Png);
    GrayAdjusted.CopyFrom(GrayBlured);

    // Adjust color
    GrayAdjusted.AdjustColor(1.5, -250);

    Png.Write(GrayOriginal, "./cballs_gray.png");
    Png.Write(GrayBlured, "./cballs_grayblured.png");
    Png.Write(GrayAdjusted, "./cballs_grayadjusted.png");

    BinaryImage Bin;

    // Example of Otsu binarization
    Bin.Otsu(GrayAdjusted);
    Png.Write(Bin, "./cballs_otsu.png");

    // Example of Niblack binarization
    Bin.Niblack(GrayAdjusted, 150, 1.5);
    Png.Write(Bin, "./cballs_niblack.png");

    // Example of Sauvola binarization
    Bin.Sauvola(GrayAdjusted, 20, 0.2);
    Png.Write(Bin, "./cballs_sauvola.png");

    Png.Read("./cballs.png");
    Cluster Objects;
    // Clusterize white objects (glowing white balls)
    uint16_t ClusterAmount = Objects.Clusterize(Bin);
    for (int i = 0; i < ClusterAmount; ++i)
    {
        const ClusterItem &item = Objects.GetCluster(i);
        Png.DrawCross(item.Cx, item.Cy, 20, PixelType::RGB24(0,255,0));
    }
    Png.Write("./cballs_clusterized.png");


    Png.Read("./cballs.png");
    
    PngImage Png2;
    Png2.Read("./cballs.png");
    AffineTransformation Affine;
    AffineTransformation Affine2;

    GrayImage Gray1, Gray2;
    Gray1.Convert(Png);

    //Affine.Shift(20, 50);
    Affine.RotateDeg(22.5);
    Affine2.Scale(2, 2);
    //Affine.Scale(0.5, 0.5);

    Affine.Transform(Affine2);

    AffineTransformationTable AffineTable;
    AffineTable.Calculate(Gray1.GetWidth(), Gray1.GetHeight(), Affine, true);
    AffineTable.Apply<InterpolationType::NearestNeighbour>(Gray1, Gray2);
    Png.Write(Gray2, "./cballs_affine.png");
    
    PngImage testPng;
    testPng.Read("./cballs.png");
    GrayImage testGray, testGray2;
    testGray.Convert(testPng);
    testGray2.CopyFrom(testGray);
    
    Sobel sobel;
    

    sobel.Calculate(testGray);
    const GenericImage<GenericPixel<int32_t , 1>> *magn = sobel.GetMagnitude();
    
    int32_t min_ = min(*magn);
    int32_t max_ = max(*magn);
    int32_t factor = max_ - min_;
    printf("%d %d %d\n", min_, max_, factor);
    auto it_src = magn->begin();
    auto it_dst = testGray.begin();
    for (; it_src != magn->end(); ++it_src, ++it_dst)
    {
        if (factor > 0)
        {
            int32_t p = it_src[0];
            p -= min_;
            it_dst[0] = (unsigned char) min(255, max(0, (255 * p) / factor));
        }
        else
        {
//.........这里部分代码省略.........
开发者ID:alex-justes,项目名称:jimlib,代码行数:101,代码来源:main.cpp


注:本文中的BinaryImage::Otsu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。