將濾鏡應用於影象修補程式並將每個畫素設定為每個修補程式的結果的平均值
許多現代影象處理演算法使用補丁是他們工作的基本要素。
例如,可以對貼片進行去噪(參見 BM3D 演算法)。
然而,當從處理過的補丁構建影象時,我們對同一畫素有很多結果。
處理它的一種方法是取同一畫素的所有值的平均值(經驗平均值)。
以下程式碼顯示瞭如何將影象分解為修補程式,並使用 [
accumarray()][1]
使用平均值從修補程式重建影象:
numRows = 5;
numCols = 5;
numRowsPatch = 3;
numColsPatch = 3;
% The Image
mI = rand([numRows, numCols]);
% Decomposing into Patches - Each pixel is part of many patches (Neglecting
% boundariwes, each pixel is part of (numRowsPatch * numColsPatch) patches).
mY = ImageToColumnsSliding(mI, [numRowsPatch, numColsPatch]);
% Here one would apply some operation which work on patches
% Creating image of the index of each pixel
mPxIdx = reshape(1:(numRows * numCols), [numRows, numCols]);
% Creating patches of the same indices
mSubsAccu = ImageToColumnsSliding(mPxIdx, [numRowsPatch, numColsPatch]);
% Reconstruct the image - Option A
mO = accumarray(mSubsAccu(:), mY(:)) ./ accumarray(mSubsAccu(:), 1);
% Reconstruct the image - Option B
mO = accumarray(mSubsAccu, mY(:), [(numRows * numCols), 1], @(x) mean(x));
% Rehsape the Vector into the Image
mO = reshape(mO, [numRows, numCols]);