void MultiBandBlender::prepare(Rect dst_roi)
{
dst_roi_final_ = dst_roi;
// Crop unnecessary bands
double max_len = static_cast<double>(std::max(dst_roi.width, dst_roi.height));
num_bands_ = std::min(actual_num_bands_, static_cast<int>(ceil(std::log(max_len) / std::log(2.0))));
// Add border to the final image, to ensure sizes are divided by (1 << num_bands_)
dst_roi.width += ((1 << num_bands_) - dst_roi.width % (1 << num_bands_)) % (1 << num_bands_);
dst_roi.height += ((1 << num_bands_) - dst_roi.height % (1 << num_bands_)) % (1 << num_bands_);
Blender::prepare(dst_roi);
dst_pyr_laplace_.resize(num_bands_ + 1);
dst_pyr_laplace_[0] = dst_;
dst_band_weights_.resize(num_bands_ + 1);
dst_band_weights_[0].create(dst_roi.size(), weight_type_);
dst_band_weights_[0].setTo(0);
for (int i = 1; i <= num_bands_; ++i)
{
dst_pyr_laplace_[i].create((dst_pyr_laplace_[i - 1].rows + 1) / 2,
(dst_pyr_laplace_[i - 1].cols + 1) / 2, CV_16SC3);
dst_band_weights_[i].create((dst_band_weights_[i - 1].rows + 1) / 2,
(dst_band_weights_[i - 1].cols + 1) / 2, weight_type_);
dst_pyr_laplace_[i].setTo(Scalar::all(0));
dst_band_weights_[i].setTo(0);
}
}
1. 确定最终ROI区域的大小
2. 确定最终的要用多少个band
3. 对感兴趣区域的宽和高进行调整,确保能被 1 << num_bands_ 整除
4. 调用Blender类下的prepare方法,创建dst_,dst_mask和把 dst_roi赋值给Blender下的成员对象dst_roi_
5. 将ROI区域赋值给dst_pyr_laplace_的第0层,拉普拉斯金字塔总共num_bands_+1 层,相应的band权重的金字塔也为 num_bands_+1 层,band权重金字塔第0层的清零
6. 金字塔第1层的宽和高是第0层的一半,同理类推,第2层是1层的一半,第3层是2层的一半… ,最终权重金字塔的每一层都清零
分析
void MultiBandBlender::feed(InputArray _img, InputArray mask, Point tl)