Identifying round objects and calculate the radius

4 views (last 30 days)
Hi everyone,
I have a tricky issue to solve so I will try my best to explain myself clearly.
I have a height field to analyze which is nammed "H" in my code : it's a 3D tensor since the first 2 dimensions represent the space (2 axis of captured images) and the last dimension corresponds to time ("H(x,y,k)" represents the height field measured on an image of coordinates (x,y) for several time values k).
Basically, what I am trying to do is to measure the radius of a certain round shaped figure that is characterized by a certain height value : this figure that evolves with time is not a perfect circle.
I am trying to build a code that helps me to :
1/ Identify for each k of the height field H : the most round-like shapes through a parameter nammed "metric" in my code.
2/ Measure the radius of this figure selected for each time time k.
This the code that I am trying to implement :
% Some useful values
coef = 3.989123911196657e-07;
H = h_reel/coefficient_2;
index_intersection = 148;
echelle = 4.294478527607363e-05;
% Initialization of the customized restricted height field "H_custom" and the radius array "radius_echelle_quint"
H_custom = zeros(401,401,index_intersection);
H_custom = single(H_custom);
radius_echelle_quint = zeros(1,index_intersection);
% We start a loop that goes through all the images for different times k
for k = 1:index_intersection
H_custom(:,:,k) = H(1000:1400,800:1200,k); % We choose a restricted zone in the field
H_custom = imbinarize(H_custom,0); % We binarize (selection of the positive values only)
H_custom = bwareaopen(H_custom,30); % We construct the external boundaries only
H_custom = imfill(H_custom,'holes'); % We fill the figures
[B_bis,L_bis] = bwboundaries(H_custom(:,:,k),'noholes');
stats_bis = regionprops(L_bis,'Area','Centroid'); % We identify the different surfaces of the different figures obtained
for i = 1:length(B_bis) % For a given time k : we identify the most circle-like figure and we try to calculate its radius
boundary = B_bis{i};
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
area_bis = stats_bis(k).Area;
metric = 4*pi*area_bis / perimeter^2; % This is the parameter to identify the round figures
metric_string = sprintf('%2.2f',metric);
if metric > 0.2 % The threshold is very low indeed...
surface_bis = stats_bis.Area;
radius_bis = sqrt(max(surface_bis/pi)); % We welect the radius of the biggest figure identified in the image
radius_echelle_quint(k) = radius_bis * echelle; % Each radius_bis calculated is stored in the global radius array that includes the calculated values for each time.
Unfortunately : this doesn't work well since I got several errors. One of them is this one :
Error using imbinarize
Expected I to be one of these types:
uint8, uint16, uint32, int8, int16, int32, single, double
Instead its type was logical.
Once I try to solve it I end up with another error :
Error using bwboundaries
Expected input number 1, BW, to be two-dimensional.
And of course, I am not able to know if the general idea of my code will be functional since the 2 loops are not very neat...
Could you help me to figure out these issues or maybe propose a more elegant way to achieve my objective ?
Thank you in advance.
P.S : I didn't attach the "H" array because it is a heavy matfile but if it's useful to help me I will share it. Also, I am attachin a typical figure that shows at a given time k : the kind of shape obtained and that I am willing to calculate the radius.
Wissem-Eddine KHATLA
Wissem-Eddine KHATLA on 21 Jan 2022
Edited: Wissem-Eddine KHATLA on 21 Jan 2022
@Image Analyst Yes of course : here is the screenshot and also the file nammes "H_custom" so no need to use the lines :
coef = 3.989123911196657e-07;
H = h_reel/coefficient_2;
index_intersection = 148;
echelle = 4.294478527607363e-05;
And :
H_custom(:,:,k) = H(1000:1400,800:1200,k); % We choose a restricted zone in the field
I saved it directly for the purpose of my question. Hope you could help : Thank you !

Sign in to comment.

Answers (0)


Find more on Convert Image Type 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!

Translated by