当前位置:   article > 正文

opencv对图像进行高斯平滑和边缘提取_图像提取轮廓转为精准的曲线

图像提取轮廓转为精准的曲线

高斯平滑:

    //对图像进行平滑处理
    cvNamedWindow( "smooth-out" );
    //当前图像结构的大小,各通道每个像素点的数据类型,通道的总数
    IplImage* out = cvCreateImage(
        cvGetSize(img),
        IPL_DEPTH_8U,
        3
    );
    cvSmooth( img, out, CV_GAUSSIAN, 3, 3 );
    cvShowImage( "smooth-out", out );
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

边缘检测和缩放,canny

IplImage* doPyrDown(
    IplImage* in,
    bool isPyr,
    double      lowThresh,
    double      highThresh,
    double      aperture)
{

    // Best to make sure input image is divisible by two.
    //
//    assert( in->width%2 == 0 && in->height%2 == 0 );

    IplImage* out = NULL;
    if(isPyr){
        out = cvCreateImage(
                cvSize( in->width/2, in->height/2 ),
                in->depth,
                in->nChannels
            );
        //cvPyrDown() 创建一幅宽度和高度为输入图像一半尺寸的图像
        cvPyrDown( in, out );
    }else{
        if(in->nChannels != 1)
            return(0);
        /*
         * Canny边缘检测将输出写入一个单通道(灰度级)图像*/
        IplImage* out = cvCreateImage(
            cvGetSize(in),
            IPL_DEPTH_8U,
            1
        );
        cvCanny( in, out, lowThresh, highThresh, aperture );
    }

    return( out );
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

itk::Image转cv::Mat

官方示例:

https://examples.itk.org/src/video/bridgeopencv/convertanitkgrayscaleimagetocvmat/documentation?highlight=opencv

itk中实现的文件:

ITK-5.3.0\Modules\Video\BridgeOpenCV\include\itkOpenCVImageBridge.hxx

在这里插入图片描述

手写测试:
** 通过itk读取单张dicom图像,然后转为cvMat,只在测试单通道,详细请看itk实现的源码 **

cv::Mat itkImageToCvImage(itk::Image<signed short, 3>::Pointer inItkImage) {
	using ImageType = itk::Image<signed short, 3>;
	const typename ImageType::RegionType  inputRegion = inItkImage->GetLargestPossibleRegion();
	const typename ImageType::SizeType    inputSize = inputRegion.GetSize();
	using InputPixelType = typename ImageType::PixelType;
	using ValueType = typename itk::NumericTraits<InputPixelType>::ValueType;

	cv::Mat cvImg;
	unsigned int w = static_cast<unsigned int>(inputSize[0]);
	unsigned int h = static_cast<unsigned int>(inputSize[1]);
	//itk读取的位SS,转到Mat位US
	cvImg = cv::Mat(h,w,CV_16U,reinterpret_cast<unsigned char *>(const_cast<InputPixelType *>(inItkImage->GetBufferPointer())));

	cv::imwrite("./gg.png", cvImg);
	return cvImg;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/899166
推荐阅读
相关标签
  

闽ICP备14008679号