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;
  1. Exclude argument checking / argument parsing functions.
  2. 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().
  3. 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]
  4. numNeighbors: contains number of neighbors of each mask pixel. (4/3/2 depends upon position)
  5. Then a sparse matrix D is generated.
  6. 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,

回答(1 个)

liumei wang
liumei wang 2019-12-31
I have the same question.

Community Treasure Hunt

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

Start Hunting!

Translated by