赞
踩
//对图像进行平滑处理
cvNamedWindow( "smooth-out" );
//当前图像结构的大小,各通道每个像素点的数据类型,通道的总数
IplImage* out = cvCreateImage(
cvGetSize(img),
IPL_DEPTH_8U,
3
);
cvSmooth( img, out, CV_GAUSSIAN, 3, 3 );
cvShowImage( "smooth-out", out );
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 );
};
官方示例:
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;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。