Can you explain mathematical interpretation of regionfillLaplace() inside regionfill(Gray, mask) function ?
2 ビュー (過去 30 日間)
古いコメントを表示
Line 230 - 255 [ regionfill() => regionfillLaplace() ]
% Form the connectivity matrix D=sparse(i,j,s)
% Connect each mask pixel to itself
i = (1:numel(maskIdx))';
j = (1:numel(maskIdx))';
% The coefficient is the number of neighbors over which we average
numNeighbors = computeNumberOfNeighbors(nRow,nCol);
s = numNeighbors(maskIdx);
% Now connect the N,E,S,W neighbors if they exist
m = nRow+2; % number of rows in grid
for direction = [-1 m 1 -m]
% Possible neighbors in the current direction
neighbors = grid(gridIdx+direction);
% Connect mask points to neighbors with -1's
i = [i; grid(gridIdx(neighbors~=0))]; %#ok<*AGROW>
j = [j; nonzeros(neighbors)];
s = [s; -ones(nnz(neighbors),1)];
end
D = sparse(i,j,s);
% Solve the linear system
sol = D \ rightSide;
% Output
J(maskIdx) = sol;
- Exclude argument checking / argument parsing functions.
- At, first the maskPerimiter is calculated, it's the outer boundary pixels of the mask regions. (neraest pixels of mask regions). It is sent as an argument to regionfillLaplace().
- Then the rightSide is calculated, It contains the sum of exixting neigbors (N,S,W,E) for each mask pixel. [interior:4, border:3, corner:2]
- numNeighbors: contains number of neighbors of each mask pixel. (4/3/2 depends upon position)
- Then a sparse matrix D is generated.
- Finally the sustem of linear equations are solved. D*sol - rightside = 0.
__________________________________________________________________
I want to understand how this sparse matrix helps/works here ? What does i, j, s actually contains. What does the for loop area (Line 240-247) perform ?
And how discrete laplace transform is implemented here ?
What is the actual mathematical logic of how each mask pixel is interpolated from its neighbor ?
__________________________________________________________________
And it seems like, each mask pixel is replaced by the average of its existing neighbors. Am I right ?
Thanks in advance,
0 件のコメント
回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!