Simulink: How to select and save coordinates from a video viewer block.
2 views (last 30 days)
Show older comments
Hello,
I am working on a project and I need help:
I have detected a red object with the help of a median filter and now want to read out and transfer the coordinates of the object.
Can someone help me please?
0 Comments
Answers (1)
Namnendra
on 6 Sep 2023
Hey Edward,
To read out and transfer the coordinates of a red object that you have detected using a median filter in MATLAB, you can follow these steps:
1. Detect the red object: Apply a median filter to your image to reduce noise and enhance the red object. You can use the 'medfilt2' function in MATLAB for this purpose.
filteredImage = medfilt2(rgbImage(:,:,1), [3 3]); % Apply median filter to red channel
2. Threshold the filtered image: Convert the filtered image to a binary image by applying a threshold. You can use the 'imbinarize' function in MATLAB and adjust the threshold value according to your specific image.
binaryImage = imbinarize(filteredImage, threshold);
3. Find connected components: Use the 'bwconncomp' function to find connected components in the binary image.
connComp = bwconncomp(binaryImage);
4. Extract object properties: Use the 'regionprops' function to extract properties of the connected components, such as centroid and bounding box.
props = regionprops(connComp, 'Centroid', 'BoundingBox');
5. Transfer the coordinates: Iterate over the detected objects' properties and extract the centroid coordinates. You can then transfer these coordinates to another application or store them in a variable for further use.
for i = 1:numel(props)
centroid = props(i).Centroid;
x = centroid(1);
y = centroid(2);
% Transfer the coordinates or store them for further use
fprintf('Object %d: x = %f, y = %f\n', i, x, y);
end
In this code snippet, the centroid coordinates ('x' and 'y') of each detected object are printed to the command window. You can modify this part to transfer the coordinates to another application or store them in a suitable data structure.
Kindly adjust the parameters and threshold values according to your specific image and requirements. Additionally, you may need to perform additional image processing steps, such as morphological operations or filtering, depending on the characteristics of your images.
Kindly refer to following links to know more:-
I hope the above information helps you.
Thank you,
Namnendra Gupta
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!