将下面代码写成matlab形式 int runBm3d( const Mat image_noisy, Mat& image_basic, Mat& image_denoised ) { int Height = image_noisy.rows; int Width = image_noisy.cols; int Channels = image_noisy.channels(); vector<Mat> block_noisy;//store the patch vector<int>row_idx;//patch idx along the row direction vector<int>col_idx; GetAllBlock(image_noisy, Width, Height, Channels, kHard, pHard, block_noisy, row_idx, col_idx); int bn_r = row_idx.size(); int bn_c = col_idx.size(); tran2d(block_noisy, kHard); vector<int> sim_num;//index number for the selected similar patch in the block vector vector<int> sim_idx_row;//index number for the selected similar patch in the original Mat vector<int> sim_idx_col; vector<Mat>data;//store the data during transforming and shrinking Mat kaiser = gen_kaiser(beta, kHard);//2-D kaiser window float weight_hd = 1.0;//weights used for current relevent patch Mat denominator_hd(image_noisy.size(), CV_32FC1, Scalar::all(0)); Mat numerator_hd(image_noisy.size(), CV_32FC1, Scalar::all(0)); for (int i = 0; i < bn_r; i++) { for (int j = 0; j < bn_c; j++) { //for each pack in the block sim_num.clear(); sim_idx_row.clear(); sim_idx_col.clear(); data.clear(); getSimilarPatch(block_noisy, data, sim_num, i, j, bn_r, bn_c, int((nHard - kHard) / pHard) + 1, NHard, tao_hard);//block matching for (int k = 0; k < sim_num.size(); k++)//calculate idx in the left-top corner { sim_idx_row.push_back(row_idx[sim_num[k] / bn_c]); sim_idx_col.push_back(col_idx[sim_num[k] % bn_c]); } tran1d(data, kHard);//3-D transforming DetectZero(data, lambda3d * sigma);//shrink the cofficient weight_hd = calculate_weight_hd(data, sigma); Inver3Dtrans(data,kHard);//3-D inverse transforming aggregation(numerator_hd, denominator_hd, sim_idx_row, sim_idx_col, data, weight_hd, kHard, kaiser);//aggregation using weigths } } image_basic = numerator_hd / denominator_hd;
时间: 2023-12-06 07:43:41 浏览: 95
function [image_basic,image_denoised] = runBm3d(image_noisy)
Height = size(image_noisy,1);
Width = size(image_noisy,2);
Channels = size(image_noisy,3);
block_noisy = {}; %store the patch
row_idx = []; %patch idx along the row direction
col_idx = [];
[block_noisy,row_idx,col_idx] = GetAllBlock(image_noisy, Width, Height, Channels, kHard, pHard);
bn_r = length(row_idx);
bn_c = length(col_idx);
block_noisy = tran2d(block_noisy, kHard);
sim_num = {}; %index number for the selected similar patch in the block vector
sim_idx_row = []; %index number for the selected similar patch in the original Mat
sim_idx_col = [];
data = {}; %store the data during transforming and shrinking
kaiser = gen_kaiser(beta, kHard); %2-D kaiser window
weight_hd = 1.0; %weights used for current relevent patch
denominator_hd = zeros(size(image_noisy),'single');
numerator_hd = zeros(size(image_noisy),'single');
for i = 1:bn_r
for j = 1:bn_c
%for each pack in the block
sim_num = {};
sim_idx_row = [];
sim_idx_col = [];
data = {};
[data,sim_num] = getSimilarPatch(block_noisy, i, j, bn_r, bn_c, int32((nHard - kHard) / pHard) + 1, NHard, tao_hard); %block matching
for k = 1:length(sim_num) %calculate idx in the left-top corner
sim_idx_row(k) = row_idx(sim_num(k) / bn_c);
sim_idx_col(k) = col_idx(mod(sim_num(k), bn_c));
end
data = tran1d(data, kHard); %3-D transforming
data = DetectZero(data, lambda3d * sigma); %shrink the cofficient
weight_hd = calculate_weight_hd(data, sigma);
data = Inver3Dtrans(data,kHard); %3-D inverse transforming
[numerator_hd, denominator_hd] = aggregation(numerator_hd, denominator_hd, sim_idx_row, sim_idx_col, data, weight_hd, kHard, kaiser); %aggregation using weigths
end
end
image_basic = numerator_hd ./ denominator_hd;
end
阅读全文