Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Can we draw two circles, one inside and the other outside of the above link circle.

Akzeptierte Antwort

Image Analyst
Image Analyst am 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 Kommentare
Naresh Naik
Naresh Naik am 2 Jan. 2013
Bearbeitet: Naresh Naik am 2 Jan. 2013
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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by