필터 지우기
필터 지우기

how can i count the number of circles with random centers and fixed diameters.

조회 수: 4 (최근 30일)
I want to get a plot of size of circles(pixels) vs. their numbers. Example 10 of 20 pixels, 15 of 10 pixels size etc.. the background should be contrast of intensity of the circles..
  댓글 수: 3
amrutha Priya
amrutha Priya 2012년 12월 4일
I did rgb to gray and counted the number of circles using the code below. but im not getting histogram of different circles. ie. size of circles vs. their number. Can u help me? Im unable to upload the image here. but the image has 45 circles with three different sizes.
path='C:\Users\Divya Bandi\Desktop\Hepatic steatosis\circles.jpg';
img=imread(path);
imshow(img);
img1=rgb2gray(img);
subplot(3,1,1);
imshow(img1);
img2=im2bw(img1,graythresh(img1));
subplot(3,1,2);
imshow(img2)
img2=~img2;
subplot(3,1,3);
imshow(img2);
B = bwboundaries(img2);
subplot(3,2,1)
imshow(img2)
text(10,10,strcat('\color{green}Objects Found:',num2str(length(B))))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2)
end

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 12월 3일
편집: Image Analyst 2012년 12월 4일
See my Image Segmentation Tutorial. It determines the size distribution of circles (coins). http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo You just need to call bar() to display them.
You might also try imfindcircles() in the Image Processing Toolbox, or see Brett's demo: http://www.mathworks.com/matlabcentral/fileexchange/34365-findcirclesgui
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Get centroid via bwboundaries and incorrect method.
rgbImage = imread('D:\Temporary stuff\welcome-green-circles-layout.jpg');
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get centroid correctly via regionprops
binaryImage = rgbImage(:,:,1) < 200;
subplot(2, 2, 2);
imshow(binaryImage);
title('Binary Image with Centroids', 'FontSize', fontSize);
hold on;
measurements = regionprops(binaryImage, 'Centroid', 'Area');
numberOfCircles = length(measurements);
allAreas = [measurements.Area]
for k = 1 : numberOfCircles
centroid = [measurements(k).Centroid];
xCenter = centroid(1);
yCenter = centroid(2);
plot(xCenter, yCenter, 'b+');
end
[counts values] = hist(allAreas);
subplot(2, 2, 3);
bar(values, counts);
grid on;
title('Histogram of Areas (the size distribution)', 'FontSize', fontSize);
message = sprintf('The number of circles is %d', numberOfCircles);
msgbox(message);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Build Interactive Tools에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by