zoukankan      html  css  js  c++  java
  • [VTK]vtkImageFlip对VTK读入图像进行翻转

     1.说说

    通过一些测试发现貌似是二维的显示的话读入的图像会保持原先的坐标系,也不会对图像进行默认的翻转,但是使用三维显示时候读入的图像会进行一定程序的翻转。

    也就是说:

    看图!

    图中,原图所示是原图,但是读入进去后变成了Mat框中显示的样子--!

    然后我对之进行水平、垂直等翻转都无法还原--!

    蛋疼,那么我以前在二维图像上求取的数据比如说轮廓中心点就木有用了--!

    怎么破--!

    后来,混沌大开,天清气朗,发现

    在reader的函数里面有一个FileLowerLeftOn据说是可以控制读入图像是否进行翻转功能。

    但是在JPEGReader里面使用读入的图像还是与原先不同。直到使用

    http://www.vtk.org/doc/nightly/html/classvtkImageFlip.html

    vtkSmartPointer<vtkImageFlip> flip = vtkSmartPointer<vtkImageFlip>::New();

    flip->SetInput(jpegReader->GetOutput());

    flip->SetFilteredAxes(1);

    稍微完整一点点的读入源代码:

    PS:要包含这个头文件不然会在flip->setInput说格式不匹配无法转换

    #include <vtkImageData.h>

        vtkSmartPointer<vtkJPEGReader> dicomReader =
            vtkSmartPointer<vtkJPEGReader>::New();  
        dicomReader->FileLowerLeftOn();
        dicomReader->SetFilePrefix("C:/Users/DawnWind/Desktop/000/");
        dicomReader->SetFilePattern("%s%d.jpg");
        dicomReader->SetDataByteOrderToLittleEndian();
        dicomReader->SetDataSpacing(2.0 / 3, 2.0 / 3, 1); 
        dicomReader->SetFileNameSliceSpacing(1); 
        dicomReader->SetDataExtent(0, 209, 0, 209, 0, 83);
        //dicomReader->SetDataExtent(0, 511, 0, 209, 0, 137);
        dicomReader->Update();  
    
        vtkSmartPointer<vtkContourFilter> skinExtractor =
            vtkSmartPointer<vtkContourFilter>::New();
        //skinExtractor->SetInputConnection(dicomReader->GetOutputPort());
    
        vtkSmartPointer<vtkImageFlip> flip = vtkSmartPointer<vtkImageFlip>::New();
        flip->SetInput(dicomReader->GetOutput());
        flip->SetFilteredAxes(1);
        skinExtractor->SetInputConnection(flip->GetOutputPort());
        //值越大,保留的部分越少。
        skinExtractor->SetValue(0, 100);    
    #ifdef LINE
        skinExtractor->Update();
        auto data = skinExtractor->GetOutput();
        auto points = data->GetPoints();
        auto pSize = points->GetNumberOfPoints();
        vector<Point3d> pointsGroup;
        Mat newMat = Mat::zeros(210, 210, CV_8UC1);
        int matStep = newMat.step;
        auto matData = newMat.data;
        Point2d center;
        for (int i = 0; i < pSize; i++)
        {
            double point[3];
            points->GetPoint(i, point);
            Point3d p1;
            p1.x = (point[0]);
            p1.y = (point[1]);
            p1.z = (point[2]);
            *(matData + (int)point[0] + (int)point[1] * matStep) = 255;
            pointsGroup.push_back(p1);
            center.x += (int)point[0];
            center.y += (int)point[1];
        }
        center.x /= pSize;
        center.y /= pSize;
        newMat.at<char>(center) = 255;
        Mat dst0;
        flip(newMat, dst0, 0);
        imshow("dst0", dst0);
        Mat dst1;
        flip(newMat, dst1, 1);
        imshow("dst1", dst1);
        Mat dstn1;
        flip(newMat, dstn1, -1);
        imshow("dstn1", dstn1);
        imshow("Mat", newMat);
        waitKey();
    #endif

    其中#ifdef里面是OpenCV代码用于读取图像并显示

    用到了Flip世界真美好(左是原图,右边是读入后提取轮廓得到的结果,可以看到没有进行翻转了)

  • 相关阅读:
    html css div img垂直居中
    jquery 多选框 checkbox 获取选中的框
    css 滚动条样式
    css 翻牌 翻转 3d翻转 特效
    css强制不换行 多出的字省略号
    jquery获取元素坐标获取鼠标坐标
    鸡汤 咯咯
    <bean> 中配置详解 </bean>
    正则表达式的囧
    我的天$删除注册表$安装mysql最后一步不能启动服务的解决办法
  • 原文地址:https://www.cnblogs.com/dawnWind/p/3D_09.html
Copyright © 2011-2022 走看看