How to remove bulbs in the mouse trajectory?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to remove the bulbs in red circles in the picture to get a smooth trajectory as shown in the picture.
The mouse may be sitting or rotating in those bulbs. My goal is to find the number of pixels (I can define my own pixel size) moved in their trajectory in the smooth profile.
I tried to divide the 2-D histogram with 50x50 bins and count the number of bins which are nonzero. Then I smoothed X and Y and plotted a 2-D histogram with 100x100 bins. I expected the number of nonzero bins to be higher in image 1 so that the number of pixels is more there. So clearly this method is not working. I have attached my code here.
How should I approach this problem?
0 Commenti
Risposta accettata
Image Analyst
il 8 Lug 2022
Try this. Adjust parameters as indicated to get what you want.
% Demo by Image Analyst
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
xcoordinates = load("xcoordinates.mat");
x = xcoordinates.ans;
ycoordinates = load('ycoordinates.mat');
y = ycoordinates.ans;
xmin = min(x); xmax = max(x);
ymin = min(y); ymax = max(y);
subplot(2, 1, 1);
plot(x, y, 'b.-');
grid on;
hold on;
% User-adjustable parameters
windowSize = 10; % Window to scan the array with.
xBoxWidth = 2.5;
yBoxWidth = 2.5;
% Scan array looking for clustered points all within the defined box width.
bulbIndexes = false(numel(x), 1);
for k = 2 : numel(x) - windowSize
% See if all x and y points in the window are within the box.
xWindow = x(k : k + windowSize - 1);
yWindow = y(k : k + windowSize - 1);
if range(xWindow) < xBoxWidth && range(yWindow) < yBoxWidth
plot(x(k : k + windowSize - 1), y(k : k + windowSize - 1), 'r.', 'MarkerSize', 10)
bulbIndexes(k : k + windowSize - 1) = true;
end
end
numPointsToBeDeleted = sum(bulbIndexes);
fprintf('Going to delete %d out of %d points.\n', numPointsToBeDeleted, numel(x))
caption = sprintf('Going to delete the %d points in red', numPointsToBeDeleted);
title(caption, 'FontSize', fontSize)
% Make a copy of the x and y
xRepaired = x;
yRepaired = y;
% Delete bulb indexes from the copies.
xRepaired(bulbIndexes) = [];
yRepaired(bulbIndexes) = [];
% Plot the repaired signals with the points deleted.
subplot(2, 1, 2);
plot(xRepaired, yRepaired, 'b.-');
grid on;
caption = sprintf('Final, repaired signal with %d points', numel(xRepaired));
title(caption, 'FontSize', fontSize)
Più risposte (1)
Image Analyst
il 3 Lug 2022
Modificato: Image Analyst
il 3 Lug 2022
Would a good algorithm be that if there is a stretch of (x,y) coordinates where the x values were all contained in a certain delta X range then we can replace the range with the interpolated path from the start of the window to the end of the window?
Another way would be to write the path to a digital image and then use morphological methods to get rid of the bulb. You'd need to specify a size for the image that wuold depend on how much spatial precision you require (like as long as we're within 1 mm of the actual location, we'll accept that).
Or you can try smoothing the trace with a Savitzky-Golay filter sgolayfilt, like in my attached demo.
Or how about if you did a cluster analysis like kmeans and if any points identified as being in the cluster were within a certain distance of the cluster centroid, find the first index and last index in the main array and interpolate a straight line between them.
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!