How to draw a circle on existed circle ? How to calculate the image shift in pixels from its center?

1 次查看(过去 30 天)
Can we draw two circles, one inside and the other outside of the above link circle.

采纳的回答

Image Analyst
Image Analyst 2013-1-1
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 个评论
Naresh Naik
Naresh Naik 2013-1-2
编辑:Naresh Naik 2013-1-2
The center of the above image is at 211 X 251 (size(IMAGE)/2)).
Let us assume if that same image center is shifted at the location 282 X 169.
Now assume we don't know this location (i.e., 282 X 169 ).
My question is how to find out the center of the the circle which is shifted (from 211 X 251 ).
Image Analyst
Image Analyst 2013-1-2
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by