gkouros / intro-to-cv-ud810

Problem Set solutions for the "Introduction to Computer Vision (ud810)" MOOC from Udacity
126 stars 50 forks source link

why does similarity.py use np.subtract(img1.shape, img2.shape).any()? #2

Closed nyck33 closed 4 years ago

nyck33 commented 4 years ago
 # if shape 
    if np.subtract(img1.shape, img2.shape).any():
        return 0
    else:
        mse = np.sum(np.subtract(img1, img2, dtype=np.float32) ** 2)
        mse /= float(img1.shape[0] * img1.shape[1])
        return np.exp(-mse / 2 / std**2)

Aren't the shapes of the images always going to be the same since the same width and height is used from particle locations to draw the bounding box for the image to be compared to the template?

gkouros commented 4 years ago

If I remember correctly I put this in place in case a particle is very close to the image borders and thus the bounding box gets clipped resulting in an image smaller than the template.

nyck33 commented 4 years ago

@gkouros thanks!

image

Actually I want to know more about what the difference is between displacement and adding noise. Displacement is deterministic in that figure where yellow points to green (sometimes multiple arrows). So even if I choose a certain particle based on its higher normalized weight during resampling, it should be displaced?

But then the next step adds probablistic noise.

Can you tell me where the corresponding lines of code are in naive_pf_tracker?

gkouros commented 4 years ago

Take a look at function resample() https://github.com/gkouros/intro-to-cv-ud810/blob/efede1b680388bc229f2dab53e0e13f9ee15c4cd/ps6_python/naive_pf_tracker.py#L54