c++ - 对 CV_16S 类型的图像进行去噪

标签 c++ opencv image-processing graphics opencv3.0

我有一个 Mat 数组,其中包含很多噪音 我只想去除图像中的噪点,但保留图像中的明亮物体。该图像的类型为 CV_16S,因此在比例尺上 (-32677, 32676)。我尝试执行 fastNLdenoise,但显然它仅适用于 CV_8UC3,如果我尝试将这些图像转换为 CV_8UC3,我会得到纯白色图像。

    for(long int FrameNumber = startFrame; FrameNumber < endFrame; FrameNumber++){

    fp.seekg( BytesPerFrame*(FrameNumber), std::ios::beg);
    char buffer[BytesPerImage];

    fp.read(buffer, BytesPerImage);
    short image[512*512];

    short min = 20000, max=1000;


    for ( int i = 0; i < BytesPerImage; i=i+2 )
    {
        int a;
        a = floor(i/2)+1;
        //  take first character
        image[a] = (static_cast<unsigned int>(static_cast<unsigned char>(buffer[i+1]))*256+static_cast<unsigned int>(static_cast<unsigned char>(buffer[i])));
        if(image[a] < min){
            min = image[a];
        }
        if(image[a] > max){
            max = image[a];
        }

    }

    // Processing the image
    Mat img(512, 512, CV_16S , image);
    img -= (min);
    img *= (32676/max); // (330000/2500);
    img *= ((max/min)/2) + 2;    // 16;
    imgArr[FrameNumber-startFrame] = img.clone();
}


Mat mean = ((imgArr[0].clone())/numFrames);
namedWindow( "Mean", WINDOW_AUTOSIZE );// Create a window for display.
for(int i = 1; i<numFrames; i++){
    mean += (imgArr[i]/numFrames);
    waitKey(50);
}


imshow("Mean", mean);

for(int i = 0; i<numFrames; i++){
    Mat temp = imgArr[i].clone();
    subtract(imgArr[i].clone(), mean, temp);
    GaussianBlur(temp, temp, Size(3,3), 1.5);
    imgArr[i] = temp.clone();
}

生成的示例图像如下所示: http://s11.postimg.org/nnhxr7j1f/Screen_Shot_2015_05_27_at_2_51_27_AM.png

最佳答案

这是我使用双边滤波器进行简单平滑的结果。希望这对您有所帮助!


Mat mSource_Bgr,mSource_Gray,mBillateral,mBillateral_Gray;
mSource_Bgr= imread(FileName_S.c_str(),1);

bilateralFilter(mSource_Bgr,mBillateral,25,36,100);

imshow("Billateral Smoothing",mBillateral);

enter image description here

Mat mCannyEdge,mThres;
cvtColor(mBillateral,mBillateral_Gray,COLOR_BGR2GRAY);

double CannyAccThresh = threshold(mBillateral_Gray,mThres,0,255,CV_THRESH_BINARY|CV_THRESH_OTSU);
double CannyThresh = 0.1 * CannyAccThresh;

Canny(mBillateral_Gray,mCannyEdge,CannyThresh,CannyAccThresh); 

Mat kernal_E,kernal_D;
int erosion_size=1,dilation_size=1;
kernal_E= getStructuringElement( MORPH_RECT,Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                                   Point( erosion_size, erosion_size ) );
kernal_D= getStructuringElement( MORPH_RECT,Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                                   Point( dilation_size, dilation_size ) );
dilate(mCannyEdge,mCannyEdge,kernal_D);
erode(mCannyEdge,mCannyEdge,kernal_E);

imshow("Canny Edge",mCannyEdge);

enter image description here

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Find contours
findContours( mCannyEdge.clone(), contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
for (int i = 0; i < contours.size(); i++)
{
    drawContours(mSource_Bgr,contours,i,Scalar(0,255,0),2);
}
imshow("Result",mSource_Bgr);

enter image description here

关于c++ - 对 CV_16S 类型的图像进行去噪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30479016/

相关文章:

c++ linux从程序执行命令行

python - 无法在Raspberry Pi 3上通过pip3安装opencv-python

asp.net - 在软件中显示太多 'skin'检测

java - 错误,还是用户错误?在裁剪后的 Mat Image 上创建边框不会正确渲染最右边的边框线

c++ - 在图像上应用均值滤波器时出现小的颜色缺陷

image-processing - 在 OpenCV 中使用 Hough 检测接近圆形的形状

c++ - 没有新成员的模板化多态派生类的大小

c++ - Box2d C++ AccessViolation 使用 b2fixture out 方法

c++ - 对称正定矩阵的特征有效逆

python - 使用OpenCV Python查找等效的imagemagick morphology命令