opencv对图像进行高斯平滑和边缘提取

高斯平滑:

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

边缘检测和缩放,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 );
};

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力减肥的小胖子5

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值