performance: vision.AlphaBlender is slower when image is big.

2 views (last 30 days)
vision.AlphaBlender is a very good function that can do a lot of "image matting", but when I encounter a large image size, the speed is very slow, look forward to the official enhancement of the efficiency of this function.
blender = vision.AlphaBlender('Operation','Binary Mask',...
'MaskSource','Input port');
% big image test performance
HH = [8000,500];
WW = [8000,500];
for i = 1:length(HH)
H = HH(i);
W = WW(i);
bottomImg = zeros(H,W,3,'single');
topImg = rand(H,W,3,'single');
maskImg = zeros(H,W,'logical');
maskImg(1:100,1:100)=1;
t1 = tic;
outImg = blender(bottomImg,topImg,maskImg);
t2 = toc(t1);
fprintf('image size:(%d*%d) take time: %.3f seconds\n',H,W,t2)
end
image size:(8000*8000) take time: 2.445 seconds image size:(500*500) take time: 0.148 seconds

Accepted Answer

cui,xingxing
cui,xingxing on 14 Mar 2023
Edited: cui,xingxing on 14 Mar 2023
There are many ways to solve this, such as rewriting the implementation of this function yourself in C/C++ and wrapping it as a mex. I now think it's not just about improving the algorithm, it's about external factors adjusting to my own needs, even if I rewrite it in an optimised C/C++ (not taking into account margin effects), such as cv::copyTo, they don't really differ much in performance, see the performance curve below.
note: uint8 type, two dims image array test

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!