How to use vision.BlobAnalysis to represent regionprops
2 views (last 30 days)
Show older comments
Hi,
I am trying to convert a program from MATLAB to C using the MATLAB Coder App. I have a lot of the code in the Image Processing Toolbox, one which will not convert using the Coder. I am trying to convert functions to the Computer Vision System Toolbox in order to convert it.
My current issue is with the function regionprops. I have a line of code as follows:
---------------------------------------------------------
% Filter the red pixels with the intensity constraints
imgbw_red = imgbw_int & imgbw_red;
% Remove small objects by erosion
se = strel('square',3);
imgbw_red = imclose(imgbw_red,se);
imgbw_red = imfill(imgbw_red,'holes');
% Find objects in the binary image
redBlobs = bwconncomp(imgbw_red);
% Compute blob properties
S = regionprops(redBlobs,'Centroid','PixelList','BoundingBox');
-----------------------------------------------------------------
The original variables are images in binary form. I believe the bwconncomp function will be unnecessary if using the function vision.BlobAnalysis, but I am unsure of how to use this function to obtain a variable equivalent to the PixelList from regionprops. This output is a p-by-q matrix that specifies the locations of pixels in the region, in coordinates. If you could give me an example of how to make this change, I would appreciate it.
Jon
0 Comments
Accepted Answer
Walter Roberson
on 3 Aug 2015
H = vision.BlobAnalysis('AreaOutputPort', false, 'CentroidOutputPort', true, 'BoundingBoxOutputPort', true, 'LabelMatrixOutputPort');
Then
[Centroids_R, BB_R, Labels_R] = step(H, imgbw_red);
Each of the outputs will be an array. The Centroids and BB will have one row per blob. The Labels will be the same size as the input. When
numblob = size(Centroids_R,1);
then
for K = 1 : numblob
[row, col] = find(Labels_R==K);
end
to get the pixel indices.
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!