Update
I decided there was too much going on (moving camera, basketball player moving a lot) in the original video I used, so I decided to record my own video of me dropping a ball
I also realized it would probably be easier to use ImageCorrelate
, since the falling object stays roughly constant in all the frames (other than that it starts to get more spread out/ blurry as it goes faster)
I recorded frames every 0.25 s from this video.
video = Import[(*downloaded video from imgur link in first paragraph*)];
frames = VideoExtractFrames[video, Range[0.5, 3.25, 0.25]];
I first started by ImageExposureCombine
ing all the frames like you did:
iec = ImageExposureCombine[frames]
I also isolated the ball from one of the frames:
ball = ImageTake[frames[[4]], {225, 255}, {290, 320}]
I then used the 2nd example in the ImageCorrelate -> Applications documentation to find the parts in iec
that look like ball
:
x = ImageCorrelate[ iec, ball, NormalizedSquaredEuclideanDistance];
mask = Dilation[ColorNegate[Binarize[x, 0.27]], DiskMatrix[12]]
Note that the binarization threshold of 0.27, and the DiskMatrix
radius of 12 are specific to this example, and probably won't work universally. Larger objects will require a larger DiskMatrix
for example.
There are still some erroneous points highlighted in mask
as well. Since the ball is dropping straight down, you could remove these by finding only the highlighted areas in a certain row range. I just found where this range was by eye. There is probably a more elegant way to do this however:
maskDat = ImageData[mask];
censoredMask =
MapIndexed[If[250 < #2[[2]] < 350, #1, 0] &, maskDat, {2}] // Image;
I then multiply this mask with the first frame in our list of frames, remove background, and compose:
res = iec*censoredMask // RemoveBackground;
ImageCompose[frames[[1]], res]
This seems to remove all the blurryness except for the ball actually moving. My phone camera is apparently not good at this high speed stuff though, so the ball becomes very dim when it's moving fast at the bottom (the bright window in the background might not help either).
Original Post