我有一个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
答案 0 :(得分:1)
以下是使用Bilateral Filter进行简单平滑的结果。希望这有帮助!
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);
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);
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);