Finding distance between centers of circles by manually selecting muliple pairs
I am having trouble finding the correct distances from circle to circle. Is there a way to select manually which circles to measure the distances between? I would need to select multiple pairs and a circle can be in a pair more than once. Then be able to advance the program when finished. Not all circles are necessary to be selected. The circle finding itself works nicely.
I included the entire code. It grabs images from a file to analyze. Thank you.
directory = uigetdir;
files = dir(fullfile(directory, ‘*.bmp’));
for k = 1:length(files)
fileName = files(k).name;
fullFilePath = fullfile(directory, fileName);
fprintf(1, ‘Processing: %sn’, fullFilePath);
rgb = imread(fullFilePath);
rgb = imcrop(rgb,[950 0 400 750]);
rgb = rgb2hsv(rgb);
rgb = rgb(:,:,3);
rgb = imadjust(rgb, [0.1 0.85]);
%rgb = im2gray(rgb);
rgb = adapthisteq(rgb);
%crop
rgb = im2bw(rgb,0.3);
%binary conversion
imshow(rgb)
d = drawline;
pos = d.Position;
diffPos = diff(pos);
diameter = hypot(diffPos(1),diffPos(2))
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’,’Sensitivity’,0.8)
imshow(rgb)
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8);
length(centers)
%
delete(h) % Delete previously drawn circles
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8,’Method’,’twostage’);
delete(h)
h = viscircles(centers,radii);
%hBright = viscircles(centersBright, radiiBright,’Color’,’b’);
h = viscircles(centers,radii);
pix = 0.00001030927835;
%calibration for pix to meter
Yp(:) = centers(:,2);
%need to do every other circle, This does distance between every one
distance = abs(diff(Yp))
%distance between center in pix
Ydiff = distance*pix
%distance between center in meters
v = 0.142082
% change this variable ‘v’ for every test run
frequency = Ydiff/v
% units 1/s
diameter = 0.00635;
% units m
Strouhal = (frequency * diameter) / v
%final strouhal number
endI am having trouble finding the correct distances from circle to circle. Is there a way to select manually which circles to measure the distances between? I would need to select multiple pairs and a circle can be in a pair more than once. Then be able to advance the program when finished. Not all circles are necessary to be selected. The circle finding itself works nicely.
I included the entire code. It grabs images from a file to analyze. Thank you.
directory = uigetdir;
files = dir(fullfile(directory, ‘*.bmp’));
for k = 1:length(files)
fileName = files(k).name;
fullFilePath = fullfile(directory, fileName);
fprintf(1, ‘Processing: %sn’, fullFilePath);
rgb = imread(fullFilePath);
rgb = imcrop(rgb,[950 0 400 750]);
rgb = rgb2hsv(rgb);
rgb = rgb(:,:,3);
rgb = imadjust(rgb, [0.1 0.85]);
%rgb = im2gray(rgb);
rgb = adapthisteq(rgb);
%crop
rgb = im2bw(rgb,0.3);
%binary conversion
imshow(rgb)
d = drawline;
pos = d.Position;
diffPos = diff(pos);
diameter = hypot(diffPos(1),diffPos(2))
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’,’Sensitivity’,0.8)
imshow(rgb)
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8);
length(centers)
%
delete(h) % Delete previously drawn circles
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8,’Method’,’twostage’);
delete(h)
h = viscircles(centers,radii);
%hBright = viscircles(centersBright, radiiBright,’Color’,’b’);
h = viscircles(centers,radii);
pix = 0.00001030927835;
%calibration for pix to meter
Yp(:) = centers(:,2);
%need to do every other circle, This does distance between every one
distance = abs(diff(Yp))
%distance between center in pix
Ydiff = distance*pix
%distance between center in meters
v = 0.142082
% change this variable ‘v’ for every test run
frequency = Ydiff/v
% units 1/s
diameter = 0.00635;
% units m
Strouhal = (frequency * diameter) / v
%final strouhal number
end I am having trouble finding the correct distances from circle to circle. Is there a way to select manually which circles to measure the distances between? I would need to select multiple pairs and a circle can be in a pair more than once. Then be able to advance the program when finished. Not all circles are necessary to be selected. The circle finding itself works nicely.
I included the entire code. It grabs images from a file to analyze. Thank you.
directory = uigetdir;
files = dir(fullfile(directory, ‘*.bmp’));
for k = 1:length(files)
fileName = files(k).name;
fullFilePath = fullfile(directory, fileName);
fprintf(1, ‘Processing: %sn’, fullFilePath);
rgb = imread(fullFilePath);
rgb = imcrop(rgb,[950 0 400 750]);
rgb = rgb2hsv(rgb);
rgb = rgb(:,:,3);
rgb = imadjust(rgb, [0.1 0.85]);
%rgb = im2gray(rgb);
rgb = adapthisteq(rgb);
%crop
rgb = im2bw(rgb,0.3);
%binary conversion
imshow(rgb)
d = drawline;
pos = d.Position;
diffPos = diff(pos);
diameter = hypot(diffPos(1),diffPos(2))
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’,’Sensitivity’,0.8)
imshow(rgb)
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8);
length(centers)
%
delete(h) % Delete previously drawn circles
h = viscircles(centers,radii);
[centers,radii] = imfindcircles(rgb,[10 400],’ObjectPolarity’,’dark’, …
‘Sensitivity’,0.8,’Method’,’twostage’);
delete(h)
h = viscircles(centers,radii);
%hBright = viscircles(centersBright, radiiBright,’Color’,’b’);
h = viscircles(centers,radii);
pix = 0.00001030927835;
%calibration for pix to meter
Yp(:) = centers(:,2);
%need to do every other circle, This does distance between every one
distance = abs(diff(Yp))
%distance between center in pix
Ydiff = distance*pix
%distance between center in meters
v = 0.142082
% change this variable ‘v’ for every test run
frequency = Ydiff/v
% units 1/s
diameter = 0.00635;
% units m
Strouhal = (frequency * diameter) / v
%final strouhal number
end image analysis MATLAB Answers — New Questions