void denoise_frame(void) { uint16_t x,y; uint32_t bad_vector = 0; /* adjust contrast for luma and chroma */ contrast_frame(); switch(denoiser.mode) { case 0: /* progressive mode */ { /* deinterlacing wanted ? */ if(denoiser.deinterlace) deinterlace(); /* Generate subsampled images */ subsample_frame (denoiser.frame.sub2ref,denoiser.frame.ref); subsample_frame (denoiser.frame.sub4ref,denoiser.frame.sub2ref); subsample_frame (denoiser.frame.sub2avg,denoiser.frame.avg); subsample_frame (denoiser.frame.sub4avg,denoiser.frame.sub2avg); for(y=32;y<(denoiser.frame.h+32);y+=8) { for(x=0;x<denoiser.frame.w;x+=8) { vector.x=0; vector.y=0; if( !low_contrast_block(x,y) && x>(denoiser.border.x) && y>(denoiser.border.y+32) && x<(denoiser.border.x+denoiser.border.w) && y<(denoiser.border.y+32+denoiser.border.h) ) { mb_search_44(x,y); mb_search_22(x,y); mb_search_11(x,y); if (mb_search_00(x,y) > denoiser.block_thres) bad_vector++; } if ( (vector.x+x)>0 && (vector.x+x)<W && (vector.y+y)>32 && (vector.y+y)<(32+H) ) { move_block(x,y); } else { vector.x=0; vector.y=0; move_block(x,y); } } } /* scene change? */ if ( denoiser.do_reset && denoiser.frame.w*denoiser.frame.h*denoiser.scene_thres/(64*100) < bad_vector) { denoiser.reset = denoiser.do_reset; } bad_vector = 0; average_frame(); correct_frame2(); denoise_frame_pass2(); sharpen_frame(); black_border(); ac_memcpy(denoiser.frame.avg[Yy],denoiser.frame.tmp[Yy],denoiser.frame.w*(denoiser.frame.h+64)); ac_memcpy(denoiser.frame.avg[Cr],denoiser.frame.tmp[Cr],denoiser.frame.w*(denoiser.frame.h+64)/4); ac_memcpy(denoiser.frame.avg[Cb],denoiser.frame.tmp[Cb],denoiser.frame.w*(denoiser.frame.h+64)/4); break; } case 1: /* interlaced mode */ { /* Generate subsampled images */ subsample_frame (denoiser.frame.sub2ref,denoiser.frame.ref); subsample_frame (denoiser.frame.sub4ref,denoiser.frame.sub2ref); subsample_frame (denoiser.frame.sub2avg,denoiser.frame.avg); subsample_frame (denoiser.frame.sub4avg,denoiser.frame.sub2avg); /* process the fields as two seperate images */ denoiser.frame.h /= 2; denoiser.frame.w *= 2; /* if lines are twice as wide as normal the offset is only 16 lines * despite 32 in progressive mode... */ for(y=16;y<(denoiser.frame.h+16);y+=8) for(x=0;x<denoiser.frame.w;x+=8) { vector.x=0; vector.y=0; if(!low_contrast_block(x,y) && x>(denoiser.border.x) && y>(denoiser.border.y+32) && x<(denoiser.border.x+denoiser.border.w) && y<(denoiser.border.y+32+denoiser.border.h) ) { mb_search_44(x,y); mb_search_22(x,y); mb_search_11(x,y); mb_search_00(x,y); } if ( (vector.x+x)>0 && (vector.x+x)<W && (vector.y+y)>32 && (vector.y+y)<(32+H) ) { move_block(x,y); } else { vector.x=0; vector.y=0; move_block(x,y); } } /* process the fields in one image again */ denoiser.frame.h *= 2; denoiser.frame.w /= 2; average_frame(); correct_frame2(); denoise_frame_pass2(); sharpen_frame(); black_border(); ac_memcpy(denoiser.frame.avg[0],denoiser.frame.tmp[0],denoiser.frame.w*(denoiser.frame.h+64)); ac_memcpy(denoiser.frame.avg[1],denoiser.frame.tmp[1],denoiser.frame.w*(denoiser.frame.h+64)/4); ac_memcpy(denoiser.frame.avg[2],denoiser.frame.tmp[2],denoiser.frame.w*(denoiser.frame.h+64)/4); break; } case 2: /* PASS II only mode */ { /* deinterlacing wanted ? */ if(denoiser.deinterlace) deinterlace(); /* as the normal denoising functions are not used we need to copy ... */ ac_memcpy(denoiser.frame.tmp[0],denoiser.frame.ref[0],denoiser.frame.w*(denoiser.frame.h+64)); ac_memcpy(denoiser.frame.tmp[1],denoiser.frame.ref[1],denoiser.frame.w*(denoiser.frame.h+64)/4); ac_memcpy(denoiser.frame.tmp[2],denoiser.frame.ref[2],denoiser.frame.w*(denoiser.frame.h+64)/4); denoise_frame_pass2(); sharpen_frame(); black_border(); break; } } }
inline cv::Mat opt_feat::Scale_Image( cv::Mat src_in, float scale_factor) { cv::Mat scaled_image, dst, tmp; tmp = src_in; //cout << "** Original Size " << tmp.cols << " & " << tmp.rows << endl; int n_cols = int(tmp.cols*scale_factor); int n_rows = int(tmp.rows*scale_factor); if (scale_factor>1) { cv::resize(tmp, dst, cv::Size(n_cols, n_rows ), CV_INTER_CUBIC ); //cout << "** New Size " << dst.cols << " & " << dst.rows << endl; int mid_col_ori = tmp.cols/2; int mid_row_ori = tmp.rows/2; int mid_col_new = dst.cols/2; int mid_row_new = dst.rows/2; int rec_col = mid_col_new - mid_col_ori; int rec_row = mid_row_new - mid_row_ori; cv::Rect roi(rec_col, rec_row, tmp.cols, tmp.rows); scaled_image = dst(roi); } else if (scale_factor==1) { scaled_image = tmp; } else { cv::resize(tmp, dst, cv::Size(n_cols, n_rows ) , CV_INTER_AREA); //cout << "** New Size " << dst.cols << " & " << dst.rows << endl; int x = (tmp.cols - dst.cols)/2; int y = (tmp.rows - dst.rows)/2; cv::Mat black_border(tmp.size(),CV_8UC3, cv::Scalar(0,0,0)); // all white image dst.copyTo( black_border( cv::Rect( x, y, dst.cols, dst.rows) ) ); scaled_image = black_border; //Adding Vertical Pixels //At the beginning cv::Mat col = tmp.col(0); for (int i=0; i<x ; ++i) { col.col(0).copyTo(scaled_image.col(i)); } //At the end col = tmp.col(tmp.cols-1); for (int i=x+dst.cols; i<tmp.cols ; ++i) { col.col(0).copyTo(scaled_image.col(i)); } //Adding horizontal pixels cv::Mat row = tmp.row(0); for (int i=0; i<y; ++i) { row.row(0).copyTo(scaled_image.row(i)); //src_in.copyTo(img_out,crop); } row = tmp.row(tmp.rows-1); for (int i=y+dst.rows; i<tmp.rows; ++i) { row.row(0).copyTo(scaled_image.row(i)); } } return scaled_image; }