how to detect circles in the provided .bmp image?

3 次查看(过去 30 天)
i am trying to detect all the possible circles in an image. I did some prprocessing to enhance the image an reduce the the noise. first of all I converted it into grayscale then did some contrast stretching and then apply median filter to remove noise. but after that i used region prop to get the area and diameter of the circles it shows just one big area and its diameter I also checked it in image region analyzer. but i want to know area and diameter of all the circles so i can place circles on that area. anyone can help me?? i have also attached the image
  2 个评论
Muhammad Imran
Muhammad Imran 2021-6-22
here is the code....
%% contrast stretching
clc
clear all;
close all;
img = rgb2gray(imread('10.bmp'));
subplot(2,2,1); imshow(img); title('Origional Image');
% d = imdistline;
% figure(1); imshow(img);
w1 = 50;
w2 = 150;
r1 = 70;
r2 = 130;
L = 255;
a = w1/r1;
b = (w2-w1)/(r2-r1);
g = (L-w2)/(L-r2);
[x y z] = size(img);
for i=1:x
for j=1:y
if img(i,j)<=r1
r=img(i,j);
elseif img(i,j)>=r1 && img(i,j)<=r2
r=img(i,j);
img(i,j)= (b*(r-r1))+w1;
else
r = img(i,j);
img(i,j)= (g*(r-r2))+w2;
end
end
end
subplot(2,2,2); imshow(img); title('Enhanced Image');
% kaverage = filter2(fspecial('average',3),img)/255;
kmedian = medfilt2(img,[20 20]);
subplot(2,2,3); imshow(kmedian); title('filtered image');
im = im2bw(kmedian);
subplot(2,2,4); imshow(im); title('Binary Image');
prop = regionprops(im, 'EquivDiameter');
allDiameters = [prop.EquivDiameter];
% im = imfill(im, 'holes');
% % subplot(2,2,4);
% figure; imshow(im); title('Filled Binary Image');

请先登录,再进行评论。

回答(1 个)

Yazan
Yazan 2021-6-30

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by