Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

How to understand the meaning of the conv operations in the function "RenderHistorgramGaussian"? #14

Open
lixiaohui2020 opened this issue Jul 22, 2021 · 2 comments

Comments

@lixiaohui2020
Copy link

lixiaohui2020 commented Jul 22, 2021

hi,
@jonbarron, thanks for sharing the codes of the ffcc. I can't understand the meaning of the conv operations in the function "RenderHistorgramGaussian". The code is as follow,

% Threshold the mahalanobis distance at 3 to make a binary mask, which is
% dilated to produce an ellipse with a dot in the center.
mask = mahal_dist <= 3;
prediction = (conv2(double(mask), ones(3,3), 'same') > 0) & ~mask;
prediction = prediction | (conv2(double(mahal_dist == min(mahal_dist(:))), [0, 1, 0; 1, 1, 1; 0, 1, 0], 'same') > 0);

% Optionally create a mask with the ground-truth white point rendered as a dot.
if ~isempty(mu_true)
  D = (us - mu_true(1)).^2 + (vs - mu_true(2)).^2;
  truth = D == min(D(:));
  truth = (conv2(double(truth), [0, 1, 0; 1, 1, 1; 0, 1, 0], 'same') > 0);
  truth = (conv2(double(truth), [0, 1, 0; 1, 1, 1; 0, 1, 0], 'same') > 0);

I want to ask the questions,

  1. What's the meaning of the function conv2(double(mask), ones(3,3), 'same') > 0) ?
  2. I can understand the formula about mahal_dist == min(mahal_dist(:) to get the ellipse of the minmum distance. However, i can't understand why to run the conv operation of the formula conv2(double(mahal_dist == min(mahal_dist(:))), [0, 1, 0; 1, 1, 1; 0, 1, 0], 'same') and why to chose the matrix [0, 1, 0; 1, 1, 1; 0, 1, 0] .
  3. Why are the two same conv operations with conv2(double(truth), [0, 1, 0; 1, 1, 1; 0, 1, 0], 'same') ?

Look forward to your favourable reply !
@jonbarron

@jonbarron
Copy link
Contributor

  1. This just dilates the mask, https://en.wikipedia.org/wiki/Dilation_(morphology). By dilating the mask and then removing the original mask, you get a boundary around the ellipse.
  2. mahal_dist == min(mahal_dist(:) just makes a single pixel at the argmin, and then it's convolved by a plus shape to make a plus. This is just because I wanted a plus shape at the center.
  3. Convolving by [0, 1, 0; 1, 1, 1; 0, 1, 0] twice just gives a nice diamond shape.
    All of this code is just for visualizing the results, and isn't critical to the algorithm.

@lixiaohui2020
Copy link
Author

@jonbarron
I am very glad to receive your prompt reply! Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants