How to draw a circle on existed circle ? How to calculate the image shift in pixels from its center?
1 view (last 30 days)
Show older comments
Can we draw two circles, one inside and the other outside of the above link circle.
0 Comments
Accepted Answer
Image Analyst
on 1 Jan 2013
You can use bwboundaries if all you want to do is draws outlines of the boundaries in the overlay above the original image:
format longg;
format compact;
clc; % Clear command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 25;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Naresh\Documents\Temporary';
baseFileName = 'imfill.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis square;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Create a binary image.
binaryImage = grayImage < 128;
subplot(2, 2, 2);
imshow(binaryImage);
axis square;
title('Binary Image', 'FontSize', fontSize);
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries.
% Display the original gray scale image.
subplot(2, 2, 3);
imshow(grayImage, []);
title('Original Grayscale Image with Outlines from bwboundaries()', 'FontSize', fontSize);
axis square;
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r-', 'LineWidth', 3);
end
hold off;
2 Comments
Image Analyst
on 2 Jan 2013
You wanted to use ginput(), so you call that and have the user click at the center. If the user clicked at the right place, ginput will return y = 282, and x = 169.
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink 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!