# Identifying round objects and calculate the radius

3 Ansichten (letzte 30 Tage)
Wissem-Eddine KHATLA am 21 Jan. 2022
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);
% 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
end
end
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.
end
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
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 ?
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.
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Wissem-Eddine KHATLA am 21 Jan. 2022
Bearbeitet: Wissem-Eddine KHATLA am 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 !

Melden Sie sich an, um zu kommentieren.

### Kategorien

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!