Tracking of black spots on a sample

3 visualizzazioni (ultimi 30 giorni)
Harry Davidson
Harry Davidson il 21 Mar 2024
Need to track the location of the black spots on this tissue sample throughout a video of about 900 frames. I've tried using histogram based tracker but its not nearly accurate enough due to background and I can't figure out how to track all the spots at once. The 2 upper left spots are most important.
Code that i tried:
%% Set up video reader and player
videoFReader = vision.VideoFileReader('Sample1.mp4',...
'VideoOutputDataType', 'double');
vidPlayer = vision.DeployableVideoPlayer;
%% Create Tracker Object
tracker = vision.HistogramBasedTracker;
%% Initialize
img = step(videoFReader);
figure
imshow(img)
h = imrect;
wait(h) ;
bocLoc = getLoc(h)
initializeObject(tracker,img(:,:,1),bocLoc);
%% Track Object
while (~isDone(videoFReader))
img = step(videoFReader);
bbox = step(tracker,img(:,:,1));
out = insertShape(img, 'Rectangle', bbox);
step(vidPlayer,out);
pause(0.1);
end
  1 Commento
Harry Davidson
Harry Davidson il 21 Mar 2024
For reference I cannot attatch the entire video 'Sample1' in the code as it is too large. The image is the first frame of the video.

Accedi per commentare.

Risposte (1)

prabhat kumar sharma
prabhat kumar sharma il 9 Mag 2024
Dear Harry,
I understand the challenges you're facing with tracking black spots in your video, I've developed a tailored approach to accurately track the black spots in your tissue sample video, focusing on the complex background and specific spots of interest. Here's a simplified overview:
1. Spot Detection
We start by identifying the black spots in each frame using advanced image processing techniques. This includes converting the image to grayscale, applying a threshold to highlight the spots, and refining their appearance for better accuracy.
2. Spot Filtering
Since you're particularly interested in the two upper left spots, we apply filters to focus only on those areas. This step ensures we concentrate our tracking efforts on the most relevant spots.
3. Spot Tracking
Finally, we use sophisticated tracking algorithms to follow these spots across the video frames. This ensures we keep a close eye on the spots you're most interested in, despite the challenging background.
%% Set up video reader
videoFReader = vision.VideoFileReader('Sample1.mp4', 'VideoOutputDataType', 'double');
%% Process and Track Spots in Each Frame
while (~isDone(videoFReader))
img = step(videoFReader); % Read next frame
grayImg = rgb2gray(img); % Convert to grayscale
% Spot detection (simple thresholding, adjust as necessary)
threshold = 0.2; % Example threshold, adjust based on your video
binaryImg = grayImg < threshold;
% Clean up binary image (remove small objects, fill holes)
cleanedImg = bwareaopen(binaryImg, 50); % Remove small objects
cleanedImg = imfill(cleanedImg, 'holes'); % Fill holes in detected spots
% Find bounding boxes around detected spots
stats = regionprops('table', cleanedImg, 'BoundingBox');
bboxes = stats.BoundingBox;
% Optional: Filter spots based on position or other criteria here
% Draw bounding boxes on the original frame
outImg = insertShape(img, 'Rectangle', bboxes, 'Color', 'red');
% Display the result
step(vidPlayer, outImg);
pause(0.1);
end
%% Cleanup
release(videoFReader);
release(vidPlayer);
This approach may require fine-tuning to adapt to the specific characteristics of your video and the nature of the spots you're tracking. Depending on your requirements, more advanced tracking algorithms or machine learning-based techniques might be necessary for optimal results.
I hope it helps!

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by